@@ -45,108 +45,6 @@ class OAuth2ImplicitGrantTests: XCTestCase
4545 XCTAssertEqual ( oauth. authURL, URL ( string: " https://auth.ful.io " ) !, " Must init `authorize_uri` " )
4646 }
4747
48- func testDeprecatedReturnURLHandling( ) {
49- let oauth = OAuth2ImplicitGrant ( settings: [
50- " client_id " : " abc " ,
51- " authorize_uri " : " https://auth.ful.io " ,
52- " keychain " : false ,
53- ] )
54-
55- // Empty redirect URL
56- oauth. onFailure = { error in
57- XCTAssertNotNil ( error, " Error message expected " )
58- XCTAssertEqual ( error, OAuth2Error . invalidRedirectURL ( " file:/// " ) )
59- }
60- oauth. afterAuthorizeOrFail = { authParameters, error in
61- XCTAssertNil ( authParameters)
62- XCTAssertNotNil ( error, " Error message expected " )
63- }
64- oauth. context. _state = " ONSTUH "
65- oauth. handleRedirectURL ( URL ( string: " file:/// " ) !)
66- XCTAssertNil ( oauth. accessToken, " Must not have an access token " )
67-
68- // No params in redirect URL
69- oauth. onFailure = { error in
70- XCTAssertNotNil ( error, " Error message expected " )
71- XCTAssertEqual ( error, OAuth2Error . invalidRedirectURL ( " https://auth.ful.io " ) )
72- }
73- oauth. handleRedirectURL ( URL ( string: " https://auth.ful.io " ) !)
74- XCTAssertNil ( oauth. accessToken, " Must not have an access token " )
75-
76- // standard error
77- oauth. context. _state = " ONSTUH " // because it has been reset
78- oauth. onFailure = { error in
79- XCTAssertNotNil ( error, " Error message expected " )
80- XCTAssertEqual ( error, OAuth2Error . accessDenied)
81- XCTAssertEqual ( error? . description, " The resource owner or authorization server denied the request. " )
82- }
83- oauth. handleRedirectURL ( URL ( string: " https://auth.ful.io#error=access_denied " ) !)
84- XCTAssertNil ( oauth. accessToken, " Must not have an access token " )
85-
86- // explicit error
87- oauth. context. _state = " ONSTUH " // because it has been reset
88- oauth. onFailure = { error in
89- XCTAssertNotNil ( error, " Error message expected " )
90- XCTAssertNotEqual ( error, OAuth2Error . generic ( " Not good " ) )
91- XCTAssertEqual ( error, OAuth2Error . responseError ( " Not good " ) )
92- XCTAssertEqual ( error? . description, " Not good " )
93- }
94- oauth. handleRedirectURL ( URL ( string: " https://auth.ful.io#error_description=Not+good " ) !)
95- XCTAssertNil ( oauth. accessToken, " Must not have an access token " )
96-
97- // no token type
98- oauth. context. _state = " ONSTUH " // because it has been reset
99- oauth. onFailure = { error in
100- XCTAssertNotNil ( error, " Error message expected " )
101- XCTAssertEqual ( error, OAuth2Error . noTokenType)
102- }
103- oauth. handleRedirectURL ( URL ( string: " https://auth.ful.io#access_token=abc&state= \( oauth. context. state) " ) !)
104- XCTAssertNil ( oauth. accessToken, " Must not have an access token " )
105-
106- // unsupported token type
107- oauth. context. _state = " ONSTUH " // because it has been reset
108- oauth. onFailure = { error in
109- XCTAssertNotNil ( error, " Error message expected " )
110- XCTAssertEqual ( error, OAuth2Error . unsupportedTokenType ( " Only “bearer” token is supported, but received “helicopter” " ) )
111- }
112- oauth. handleRedirectURL ( URL ( string: " https://auth.ful.io#token_type=helicopter&access_token=abc&state= \( oauth. context. state) " ) !)
113- XCTAssertNil ( oauth. accessToken, " Must not have an access token " )
114-
115- // Invalid state
116- oauth. context. _state = " ONSTUH " // because it has been reset
117- oauth. onFailure = { error in
118- XCTAssertNotNil ( error, " Error message expected " )
119- XCTAssertEqual ( error, OAuth2Error . invalidState)
120- }
121- oauth. handleRedirectURL ( URL ( string: " https://auth.ful.io#token_type=bearer&access_token=abc&state=ONSTOH " ) !)
122- XCTAssertNil ( oauth. accessToken, " Must not have an access token " )
123-
124- // success 1
125- oauth. onFailure = { error in
126- XCTAssertTrue ( false , " Should not call this " )
127- }
128- oauth. afterAuthorizeOrFail = { authParameters, error in
129- XCTAssertNotNil ( authParameters, " Expecting non-nil auth dict " )
130- XCTAssertTrue ( ( authParameters? . count ?? 0 ) > 2 , " Expecting non-empty auth dict " )
131- XCTAssertNil ( error, " No error message expected " )
132- }
133- oauth. handleRedirectURL ( URL ( string: " https://auth.ful.io#token_type=bearer&access_token=abc&state= \( oauth. context. state) &expires_in=3599 " ) !)
134- XCTAssertNotNil ( oauth. accessToken, " Must have an access token " )
135- XCTAssertEqual ( oauth. accessToken!, " abc " )
136- XCTAssertNotNil ( oauth. accessTokenExpiry)
137- XCTAssertTrue ( oauth. hasUnexpiredAccessToken ( ) )
138-
139- // success 2
140- oauth. onFailure = { error in
141- XCTAssertTrue ( false , " Should not call this " )
142- }
143- oauth. handleRedirectURL ( URL ( string: " https://auth.ful.io#token_type=bearer&access_token=abc&state= \( oauth. context. state) " ) !)
144- XCTAssertNotNil ( oauth. accessToken, " Must have an access token " )
145- XCTAssertEqual ( oauth. accessToken!, " abc " )
146- XCTAssertNil ( oauth. accessTokenExpiry)
147- XCTAssertTrue ( oauth. hasUnexpiredAccessToken ( ) )
148- }
149-
15048 func testReturnURLHandling( ) {
15149 let oauth = OAuth2ImplicitGrant ( settings: [
15250 " client_id " : " abc " ,
0 commit comments