@@ -12,6 +12,8 @@ import Foundation
12
12
13
13
class SignatureTestSuite : XCTestCase {
14
14
static var allTests = [
15
+ ( " testGetUnreserved " , testGetUnreserved) ,
16
+ ( " testGetUTF8 " , testGetUTF8) ,
15
17
( " testPostVanilla " , testPostVanilla) ,
16
18
( " testPostVanillaQuery " , testPostVanillaQuery) ,
17
19
( " testPostVanillaQueryNonunreserved " , testPostVanillaQueryNonunreserved)
@@ -24,6 +26,45 @@ class SignatureTestSuite: XCTestCase {
24
26
return _dateFormatter
25
27
} ( )
26
28
29
+ func testGetUnreserved( ) {
30
+ let expectedCanonicalRequest = " GET \n /-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \n \n host:example.amazonaws.com \n x-amz-date:20150830T123600Z \n \n host;x-amz-date \n e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 "
31
+
32
+ let expectedCredentialScope = " 20150830/us-east-1/service/aws4_request "
33
+
34
+ let expectedCanonicalHeaders : [ HeaderKey : String ] = [
35
+ " X-Amz-Date " : " 20150830T123600Z " ,
36
+ " Authorization " : " AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=07ef7494c76fa4850883e2b006601f940f8a34d404d0cfa977f52a65bbf5f24f "
37
+ ]
38
+
39
+ let result = sign (
40
+ method: . get,
41
+ path: " /-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz "
42
+ )
43
+ result. expect (
44
+ canonicalRequest: expectedCanonicalRequest,
45
+ credentialScope: expectedCredentialScope,
46
+ canonicalHeaders: expectedCanonicalHeaders
47
+ )
48
+ }
49
+
50
+ func testGetUTF8( ) {
51
+ let expectedCanonicalRequest = " GET \n /%E1%88%B4 \n \n host:example.amazonaws.com \n x-amz-date:20150830T123600Z \n \n host;x-amz-date \n e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 "
52
+
53
+ let expectedCredentialScope = " 20150830/us-east-1/service/aws4_request "
54
+
55
+ let expectedCanonicalHeaders : [ HeaderKey : String ] = [
56
+ " X-Amz-Date " : " 20150830T123600Z " ,
57
+ " Authorization " : " AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=8318018e0b0f223aa2bbf98705b62bb787dc9c0e678f255a891fd03141be5d85 "
58
+ ]
59
+
60
+ let result = sign ( method: . get, path: " /ሴ " )
61
+ result. expect (
62
+ canonicalRequest: expectedCanonicalRequest,
63
+ credentialScope: expectedCredentialScope,
64
+ canonicalHeaders: expectedCanonicalHeaders
65
+ )
66
+ }
67
+
27
68
func testPostVanilla( ) {
28
69
let expectedCanonicalRequest = " POST \n / \n \n host:example.amazonaws.com \n x-amz-date:20150830T123600Z \n \n host;x-amz-date \n e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 "
29
70
@@ -34,7 +75,7 @@ class SignatureTestSuite: XCTestCase {
34
75
" Authorization " : " AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5da7c1a2acd57cee7505fc6676e4e544621c30862966e37dddb68e92efbe5d6b "
35
76
]
36
77
37
- let result = post ( path: " / " )
78
+ let result = sign ( method : . post , path: " / " )
38
79
result. expect (
39
80
canonicalRequest: expectedCanonicalRequest,
40
81
credentialScope: expectedCredentialScope,
@@ -52,7 +93,7 @@ class SignatureTestSuite: XCTestCase {
52
93
" Authorization " : " AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=28038455d6de14eafc1f9222cf5aa6f1a96197d7deb8263271d420d138af7f11 "
53
94
]
54
95
55
- let result = post ( path: " / " , requestParam: " Param1=value1 " )
96
+ let result = sign ( method : . post , path: " / " , requestParam: " Param1=value1 " )
56
97
result. expect (
57
98
canonicalRequest: expectedCanonicalRequest,
58
99
credentialScope: expectedCredentialScope,
@@ -70,7 +111,7 @@ class SignatureTestSuite: XCTestCase {
70
111
" Authorization " : " AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=88d3e39e4fa54b971f51c0a09140368e1a51aafb76c4652d9998f93cf3038074 "
71
112
]
72
113
73
- let result = post ( path: " / " , requestParam: " @#$%^&+=/,?><` \" ;: \\ |][{} " )
114
+ let result = sign ( method : . post , path: " / " , requestParam: " @#$%^&+=/,?><` \" ;: \\ |][{} " )
74
115
result. expect (
75
116
canonicalRequest: expectedCanonicalRequest,
76
117
credentialScope: expectedCredentialScope,
@@ -85,9 +126,13 @@ extension SignatureTestSuite {
85
126
return SignatureTestSuite . dateFormatter. date ( from: " 20150830T123600Z " ) !
86
127
}
87
128
88
- func post( path: String , requestParam: String ? = nil ) -> SignerResult {
129
+ func sign(
130
+ method: Driver . Authentication . Method ,
131
+ path: String ,
132
+ requestParam: String ? = nil
133
+ ) -> SignerResult {
89
134
var auth = Driver . Authentication (
90
- method: . post ,
135
+ method: method ,
91
136
service: " service " ,
92
137
host: " example.amazonaws.com " ,
93
138
region: " us-east-1 " ,
0 commit comments