Skip to content

Commit a381056

Browse files
Update Drive Axle API Key Authorization Header (#13)
1 parent 3ad6429 commit a381056

3 files changed

Lines changed: 180 additions & 7 deletions

File tree

.circleci/config.yml

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
version: 2.1
22

33
orbs:
4+
# If you update this value, be sure to check that build_powershell_five is still getting Powershell 5
45
win: circleci/windows@2.2.0
56

6-
jobs:
7-
build:
8-
executor:
9-
name: win/default
10-
shell: powershell.exe
7+
commands:
8+
powershell_version_setup:
9+
parameters:
10+
powershell_setup_steps:
11+
description: setup steps needed for the configured powershell version to run
12+
type: steps
13+
default: []
14+
steps:
15+
- steps: << parameters.powershell_setup_steps >>
16+
17+
run_tests:
1118
steps:
12-
- checkout
1319
- run: |
1420
$module = "C:\Program Files\WindowsPowerShell\Modules\Pester"
1521
takeown /F $module /A /R
@@ -23,10 +29,65 @@ jobs:
2329
$job = start-job {dotnet run --project C:\Users\circleci\project\MockServer\MockServer}
2430
Start-Sleep 10
2531
.\Tests\doc-downloader.tests.ps1
32+
.\Tests\drive-axle-doc-downloader.tests.ps1
33+
34+
jobs:
35+
build_powershell_five:
36+
executor:
37+
name: win/default
38+
shell: powershell.exe
39+
steps:
40+
- checkout
41+
- run_tests
42+
build_powershell_six:
43+
executor:
44+
name: win/default
45+
shell: powershell.exe
46+
steps:
47+
- checkout
48+
- powershell_version_setup:
49+
powershell_setup_steps:
50+
- run: |
51+
choco install powershell-core
52+
choco uninstall powershell-core
53+
choco install powershell-core --version=6.2.4
54+
cd 'C:\Program Files\PowerShell\6'
55+
.\pwsh.exe
56+
- run_tests
57+
build_powershell_seven:
58+
executor:
59+
name: win/default
60+
shell: powershell.exe
61+
steps:
62+
- checkout
63+
- powershell_version_setup:
64+
powershell_setup_steps:
65+
- run: |
66+
choco install powershell-core --version=7.3.0
67+
pwsh.exe
68+
- run_tests
69+
store_artifacts:
70+
executor:
71+
name: win/default
72+
shell: powershell.exe
73+
steps:
74+
- checkout
2675
- run: |
2776
Write-Host (Split-Path -Path $PSScriptRoot)
2877
$ProgressPreference = 'SilentlyContinue';
2978
Compress-Archive -Path "C:\Users\circleci\project\README.txt", "C:\Users\circleci\project\configurations.json", "C:\Users\circleci\project\*.ps1" -DestinationPath document-downloader.zip
3079
- store_artifacts:
3180
path: document-downloader.zip
3281
destination: document-downloader.zip
82+
83+
84+
workflows:
85+
version: 2
86+
build_with_powershell_versions:
87+
jobs:
88+
- build_powershell_five
89+
- build_powershell_six
90+
- build_powershell_seven
91+
- store_artifacts
92+
93+
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path)
2+
$src = Split-Path -Path $here -Parent
3+
. $src\doc-downloader.functions.ps1
4+
5+
$testfile = ($here + "\LogFile.txt")
6+
7+
$API_KEY = "api-keys-are-cool"
8+
$BASE_URL = 'http://localhost:5000'
9+
$DRIVE_AXLE_HEADERS = @{ Authorization = ("DriveAxleKey key=" + $API_KEY)
10+
Accept = 'application/json'}
11+
12+
if((Test-Path $testfile) -ne $True){
13+
New-Item -Path $testfile -ItemType File
14+
}
15+
16+
Describe "Consume API Function Tests" {
17+
Context 'Testing GetNextDoc function' {
18+
it 'GetNextDoc should return a 302 if there is a document in the queue' {
19+
$request = $BASE_URL + '/api/v1/documents/queued/next'
20+
$response = GetNextDoc $request $DRIVE_AXLE_HEADERS $testfile
21+
$response.StatusCode | should -Be 302
22+
}
23+
it 'GetNextDoc should return a 304 if there is not a document in the queue' {
24+
$request = $BASE_URL + '/api/v1/documents/queued/next/empty'
25+
$response = GetNextDoc $request $DRIVE_AXLE_HEADERS $testfile
26+
$response.StatusCode | should -Be 304
27+
}
28+
29+
it 'GetNextDoc should throw an expection if a 404 status code is returned' {
30+
$request = $BASE_URL + '/api/v1/documents/queued/next/fail'
31+
$exception = $false
32+
try {
33+
GetNextDoc $request $DRIVE_AXLE_HEADERS $testfile
34+
}
35+
catch {
36+
$exception = $_.CategoryInfo.Reason -eq 'WebException'
37+
}
38+
$exception | Should -Be $true
39+
}
40+
41+
42+
it 'GetNextDoc should throw an exception if a 500 status code is returned' {
43+
$request = $BASE_URL + '/api/v1/documents/queued/next/badserver'
44+
$exception = $false
45+
try{
46+
$request = GetNextDoc $request $DRIVE_AXLE_HEADERS $testfile -ErrorAction SilentlyContinue
47+
}
48+
catch {
49+
$exception = $_.CategoryInfo.Reason -eq "WebException"
50+
}
51+
$exception | Should -Be $true
52+
}
53+
}
54+
55+
Context 'Testing GetDocFromQueue function' {
56+
it 'GetDocFromQueue should return a 200 with a URL to download document' {
57+
$request = $BASE_URL + '/api/v1/documents/queued/1'
58+
$response = GetDocFromQueue $request $DRIVE_AXLE_HEADERS $testfile
59+
$response.StatusCode | should -Be 200
60+
$response = $response | ConvertFrom-Json
61+
$response.downloadUrl | should -Not -Be $null
62+
}
63+
64+
it 'GetDocFromQueue should throw an exception if a 404 status code is returned' {
65+
$request = $BASE_URL + '/api/v1/documents/queued/2'
66+
$exception = $false
67+
try{
68+
$request = GetNextDoc $request $DRIVE_AXLE_HEADERS $testfile -ErrorAction SilentlyContinue
69+
}
70+
catch {
71+
$exception = $_.CategoryInfo.Reason -eq 'WebException'
72+
}
73+
$exception | Should -Be $true
74+
}
75+
76+
it 'GetDocFromQueue should throw an exception if a 500 status code is returned' {
77+
$request = $BASE_URL + '/api/v1/documents/queued/2'
78+
$exception = $false
79+
try{
80+
$request = GetNextDoc $request $DRIVE_AXLE_HEADERS $testfile -ErrorAction SilentlyContinue
81+
}
82+
catch {
83+
$exception = $_.CategoryInfo.Reason -eq 'WebException'
84+
}
85+
$exception | Should -Be $true
86+
}
87+
}
88+
89+
Context 'Testing RemoveDocFromQueue function' {
90+
it 'RemoveDocFromQueue should return a 200 if a document was successfully removed from the queue' {
91+
$request = $BASE_URL + '/api/v1/documents/queued/1'
92+
$response = RemoveDocFromQueue $request $DRIVE_AXLE_HEADERS $testfile
93+
$response = $response | ConvertFrom-Json
94+
$response.message | Should -Be "Document deleted successfully."
95+
}
96+
it 'RemoveDocFromQueue should return null if the document to be removed could not be found' {
97+
$request = $BASE_URL + '/api/v1/documents/queued/2'
98+
$response = RemoveDocFromQueue $request $DRIVE_AXLE_HEADERS $testfile
99+
$response | should -Be $null
100+
}
101+
}
102+
103+
Context 'Testing ExponentialDeleteRetry function' {
104+
it 'ExpWait should return a null if the document is never removed after the multiple retires due to 404 not found' {
105+
$request = $BASE_URL + '/api/v1/documents/queued/3'
106+
$response = ExponentialDeleteRetry $request $DRIVE_AXLE_HEADERS $testfile
107+
$response | should -Be $null
108+
}
109+
}
110+
}
111+
112+

doc-downloader.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If($DATED_FOLDERS) {
2929
Else {
3030
$FILE_DIR = $DESTINATION_PATH}
3131

32-
$DRIVE_AXLE_HEADERS = @{ Authorization = ("driveaxle=" + $API_KEY)
32+
$DRIVE_AXLE_HEADERS = @{ Authorization = ("DriveAxleKey key=" + $API_KEY)
3333
Accept = 'application/json'
3434
ContentType = 'application/json'}
3535

0 commit comments

Comments
 (0)