Skip to content

Commit 418f611

Browse files
committed
Provide proxy config to git
1 parent 84e7cf7 commit 418f611

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ jobs:
2121
- name: Test Scoop Installer
2222
shell: powershell
2323
run: ./test/bin/test.ps1
24+
- name: Test Scoop Install command
25+
shell: powershell
26+
run: |
27+
./install.ps1 -RunAsAdmin
28+
echo "$Env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
29+
- name: Test scoop command availability
30+
shell: powershell
31+
run: scoop status
2432
test_pwsh:
2533
name: PowerShell
2634
runs-on: windows-latest
@@ -37,3 +45,11 @@ jobs:
3745
- name: Test Scoop Installer
3846
shell: pwsh
3947
run: ./test/bin/test.ps1
48+
- name: Test Scoop Install command
49+
shell: pwsh
50+
run: |
51+
./install.ps1 -RunAsAdmin
52+
echo "~\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
53+
- name: Test scoop command availability
54+
shell: pwsh
55+
run: scoop status

install.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
.PARAMETER Proxy
4646
Specifies proxy to use during the installation.
4747
.PARAMETER ProxyCredential
48-
Specifies credential for the given prxoy.
48+
Specifies credential for the given proxy.
4949
.PARAMETER ProxyUseDefaultCredentials
5050
Use the credentials of the current user for the proxy server that is specified by the -Proxy parameter.
5151
.PARAMETER RunAsAdmin
@@ -498,15 +498,21 @@ function Install-Scoop {
498498
# Enable TLS 1.2
499499
Optimize-SecurityProtocol
500500

501+
# Download scoop from GitHub
502+
Write-InstallInfo "Downloading ..."
503+
$downloader = Get-Downloader
504+
501505
if (Test-Command-Available('git')) {
506+
if ($downloader.Proxy) {
507+
#define env vars for git when behind a proxy
508+
$Env:HTTP_PROXY = $downloader.Proxy.Address
509+
$Env:HTTPS_PROXY = $downloader.Proxy.Address
510+
}
502511
Write-Verbose "Cloning $SCOOP_PACKAGE_GIT_REPO to $SCOOP_APP_DIR"
503512
git clone $SCOOP_PACKAGE_GIT_REPO $SCOOP_APP_DIR
504513
Write-Verbose "Cloning $SCOOP_MAIN_BUCKET_GIT_REPO to $SCOOP_MAIN_BUCKET_DIR"
505514
git clone $SCOOP_MAIN_BUCKET_GIT_REPO $SCOOP_MAIN_BUCKET_DIR
506515
} else {
507-
# Download scoop zip from GitHub
508-
Write-InstallInfo "Downloading..."
509-
$downloader = Get-Downloader
510516
# 1. download scoop
511517
$scoopZipfile = "$SCOOP_APP_DIR\scoop.zip"
512518
if (!(Test-Path $SCOOP_APP_DIR)) {

test/install.Tests.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BeforeAll {
2+
# Load SUT
3+
$sut = (Split-Path -Leaf $PSCommandPath).Replace('.Tests.ps1', '.ps1')
4+
. ".\$sut"
5+
}
6+
7+
Describe 'Get-Downloader' -Tag 'Proxy' {
8+
Context 'No proxy given via script parameter' {
9+
It 'Returns WebClient without proxy' {
10+
$NoProxy = $true
11+
Test-ValidateParameter
12+
(Get-Downloader).Proxy | Should -Be $null
13+
}
14+
It 'Returns WebClient without proxy although proxy is given' {
15+
$NoProxy = $true
16+
$Proxy = New-Object System.Uri('http://donotcare')
17+
Test-ValidateParameter
18+
(Get-Downloader).Proxy | Should -Be $null
19+
}
20+
}
21+
Context 'Proxy given via script parameter' {
22+
It 'Returns WebClient with proxy' {
23+
$ProxyString = 'http://some.proxy.with.port:8080'
24+
$Proxy = New-Object System.Uri($ProxyString)
25+
Test-ValidateParameter
26+
(Get-Downloader).Proxy.Address | Should -Be "$ProxyString/"
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)