Skip to content

Commit 85dc65a

Browse files
committed
chore: add unit tests for parsing claims (#1692)
1 parent afb8c5a commit 85dc65a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

AmplifyPlugins/Core/AWSPluginsCoreTests/Auth/AWSAuthServiceTests.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,53 @@ class AWSAuthServiceTests: XCTestCase {
104104
}
105105
XCTAssertEqual(jsonDecodeError.code, 3_840)
106106
}
107+
108+
func testClaimsWithSpecialCharacters() throws {
109+
let tokenString = """
110+
eyJraWQiOiJaS0s5ZUlZbmo4UEtGQzUrMHdMQUhJMjd0SWcxRkRRZU9ybW82SVwvdFkwbz0iLCJhbGciOiJSUzI1NiJ9\
111+
.eyJmYy1pZCI6IjE2ZjFkOTM3LTY5YmQtNGI2OS1hMzJmLWYwNjkxNGY0YzIxOCIsInN1YiI6IjE2ZjFkOTM3LTY5YmQ\
112+
tNGI2OS1hMzJmLWYwNjkxNGY0YzIxOCIsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTEuYW1hem9\
113+
uYXdzLmNvbVwvdXMtZWFzdC0xXzhqRVI4cHY0ViIsImNvZ25pdG86dXNlcm5hbWUiOiIxNmYxZDkzNy02OWJkLTRiNjk\
114+
tYTMyZi1mMDY5MTRmNGMyMTgiLCJnaXZlbl9uYW1lIjoiQm_DsWEiLCJhdWQiOiI2bTZ1dWlocmhzM3BzbGI0amhhdHJ\
115+
zYnBxYyIsImV2ZW50X2lkIjoiYjAzZjQ1YWMtM2FlMS0xMWU5LTlkZDItODcyODBlYTRiMGNhIiwidG9rZW5fdXNlIjo\
116+
iaWQiLCJhdXRoX3RpbWUiOjE1NTEzMDc2NjEsImV4cCI6MTU1MTMxMTI2MSwiaWF0IjoxNTUxMzA3NjYxLCJmYW1pbHl\
117+
fbmFtZSI6IkJhcsOnYSIsImVtYWlsIjoiaW5mb0Bkb25hYmFyY2EzLmRlIn0.OGT9siqf_tAYrhVA-EhYabz-L4ZNLe0\
118+
w0N7fH4rASs0scRGm-34g96qmSZoD1j74bplIRcMqoFaDI0cLejyeeLN-z2ib1MDsuMnyq8cHfuu4x4qBGVcxWGkIOBj\
119+
AEdsiU5U4xsEuaRpgC1rNiS7X6t0vQsDj3Jw3cV1XmJbeHaZB8D7EUMW6-zk4ZT2jKrpiaeaPTFoJJFOYiYdlJj4zkxX\
120+
T2nzldS9K57Mwz91YgbjF_VCxPl84b-aiBoj7_ARdu8LDP2HHkpVoNslWYuusatBOOJvTT56Fa2kJzZqoUuAnGiC8AYU\
121+
_YKpL_iu-wv5xnWHthuDCxhpl85cdROrAbA
122+
"""
123+
124+
let claimsResult = awsAuthService.getTokenClaims(tokenString: tokenString)
125+
XCTAssertNotNil(claimsResult)
126+
guard case .success(let claims) = claimsResult else {
127+
XCTFail("Unable to parse claims")
128+
return
129+
}
130+
131+
guard let givenName = claims["given_name"] as? String else {
132+
XCTFail("Claim should contain name")
133+
return
134+
}
135+
XCTAssertEqual(givenName, "Boña")
136+
137+
guard let familyName = claims["family_name"] as? String else {
138+
XCTFail("Claim should contain sub")
139+
return
140+
}
141+
XCTAssertEqual(familyName, "Barça")
142+
143+
guard let iat = claims["iat"] as? Int else {
144+
XCTFail("Claim should contain iat")
145+
return
146+
}
147+
148+
guard let sub = claims["sub"] as? String else {
149+
XCTFail("Claim should contain sub")
150+
return
151+
}
152+
XCTAssertEqual(sub, "16f1d937-69bd-4b69-a32f-f06914f4c218")
153+
154+
XCTAssertEqual(iat, 1_551_307_661)
155+
}
107156
}

0 commit comments

Comments
 (0)