diff --git a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift index 47e1f85..49d0ad8 100644 --- a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift +++ b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationRequestTests.swift @@ -6,8 +6,6 @@ class AuthorizationRequestTests: XCTestCase { // MARK: - Properties var app: Application! - /// used for some but not all tests - var customApp: Application? var fakeClientRetriever: FakeClientGetter! var capturingAuthoriseHandler: CapturingAuthoriseHandler! @@ -35,7 +33,6 @@ class AuthorizationRequestTests: XCTestCase { override func tearDown() async throws { app.shutdown() - customApp?.shutdown() try await super.tearDown() } @@ -224,7 +221,8 @@ class AuthorizationRequestTests: XCTestCase { } func testThatUnknownScopeReturnsInvalidScopeError() async throws { - customApp = try TestDataBuilder.getOAuth2Application( + app.shutdown() + app = try TestDataBuilder.getOAuth2Application( clientRetriever: fakeClientRetriever, authorizeHandler: capturingAuthoriseHandler, validScopes: ["email", "profile", "admin"] @@ -234,8 +232,7 @@ class AuthorizationRequestTests: XCTestCase { let response = try await respondToOAuthRequest( clientID: clientID, redirectURI: redirectURI, - scope: invalidScope, - on: customApp! + scope: invalidScope ) XCTAssertEqual(response.status, .seeOther) @@ -295,7 +292,8 @@ class AuthorizationRequestTests: XCTestCase { } func testNonHTTPSRedirectURICanNotBeUsedWhenInProduction() async throws { - customApp = try TestDataBuilder.getOAuth2Application( + app.shutdown() + app = try TestDataBuilder.getOAuth2Application( clientRetriever: fakeClientRetriever, authorizeHandler: capturingAuthoriseHandler, environment: .production @@ -309,7 +307,7 @@ class AuthorizationRequestTests: XCTestCase { ) fakeClientRetriever.validClients[clientID] = httpClient - _ = try await respondToOAuthRequest(clientID: clientID, redirectURI: nonHTTPSRedirectURI, on: customApp!) + _ = try await respondToOAuthRequest(clientID: clientID, redirectURI: nonHTTPSRedirectURI) XCTAssertEqual(capturingAuthoriseHandler.authorizationError, .httpRedirectURI) } @@ -372,11 +370,9 @@ class AuthorizationRequestTests: XCTestCase { clientID: String?, redirectURI: String?, scope: String? = nil, - state: String? = nil, - on customApp: Application? = nil + state: String? = nil ) async throws -> XCTHTTPResponse { - let app: Application! = customApp ?? self.app - return try await TestDataBuilder.getAuthRequestResponse( + try await TestDataBuilder.getAuthRequestResponse( with: app, responseType: responseType, clientID: clientID, diff --git a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift index 78ec3e1..5a960f9 100644 --- a/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift +++ b/Tests/VaporOAuthTests/AuthorizationTests/AuthorizationResponseTests.swift @@ -6,7 +6,6 @@ class AuthorizationResponseTests: XCTestCase { // MARK: - Properties var app: Application! - var customApp: Application? var fakeClientRetriever: FakeClientGetter! var capturingAuthoriseHandler: CapturingAuthoriseHandler! var fakeCodeManager: FakeCodeManager! @@ -50,7 +49,6 @@ class AuthorizationResponseTests: XCTestCase { override func tearDown() async throws { app.shutdown() - customApp?.shutdown() try await super.tearDown() } @@ -130,7 +128,9 @@ class AuthorizationResponseTests: XCTestCase { } func testThatRedirectURIMustBeHTTPSForProduction() async throws { - customApp = try TestDataBuilder.getOAuth2Application( + app.shutdown() + + app = try TestDataBuilder.getOAuth2Application( clientRetriever: fakeClientRetriever, authorizeHandler: capturingAuthoriseHandler, environment: .production, @@ -142,7 +142,7 @@ class AuthorizationResponseTests: XCTestCase { let newClient = OAuthClient(clientID: clientID, redirectURIs: [redirectURI], allowedGrantType: .authorization) fakeClientRetriever.validClients[clientID] = newClient - let response = try await getAuthResponse(clientID: clientID, redirectURI: redirectURI, on: customApp!) + let response = try await getAuthResponse(clientID: clientID, redirectURI: redirectURI) XCTAssertEqual(response.status, .badRequest) } @@ -308,11 +308,9 @@ class AuthorizationResponseTests: XCTestCase { state: String? = nil, user: OAuthUser? = TestDataBuilder.anyOAuthUser(), csrfToken: String? = "the-csrf-token", - sessionID: String? = "the-session-ID", - on customApp: Application? = nil + sessionID: String? = "the-session-ID" ) async throws -> XCTHTTPResponse { - let app: Application! = customApp ?? self.app - return try await TestDataBuilder.getAuthResponseResponse( + try await TestDataBuilder.getAuthResponseResponse( with: app, approve: approve, clientID: clientID, diff --git a/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift b/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift index 88c77f2..36bb262 100644 --- a/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift +++ b/Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift @@ -4,8 +4,6 @@ import XCTVapor class ImplicitGrantTests: XCTestCase { // MARK: - Properties var app: Application! - // used for some, but not all tests - var customApp: Application? var fakeClientGetter: FakeClientGetter! var fakeTokenManager: FakeTokenManager! var capturingAuthHandler: CapturingAuthoriseHandler! @@ -51,7 +49,6 @@ class ImplicitGrantTests: XCTestCase { override func tearDown() async throws { app.shutdown() - customApp?.shutdown() try await super.tearDown() } @@ -245,7 +242,8 @@ class ImplicitGrantTests: XCTestCase { } func testThatRedirectURIMustBeHTTPSForProduction() async throws { - customApp = try TestDataBuilder.getOAuth2Application( + app.shutdown() + app = try TestDataBuilder.getOAuth2Application( clientRetriever: fakeClientGetter, authorizeHandler: capturingAuthHandler, environment: .production, @@ -257,7 +255,7 @@ class ImplicitGrantTests: XCTestCase { let newClient = OAuthClient(clientID: clientID, redirectURIs: [redirectURI], allowedGrantType: .implicit) fakeClientGetter.validClients[clientID] = newClient - let response = try await getImplicitGrantResponse(clientID: clientID, redirectURI: redirectURI, on: customApp!) + let response = try await getImplicitGrantResponse(clientID: clientID, redirectURI: redirectURI) XCTAssertEqual(response.status, .badRequest) } @@ -352,7 +350,8 @@ class ImplicitGrantTests: XCTestCase { fakeTokenManager.accessTokenToReturn = accessToken let user = OAuthUser(userID: userID, username: "luke", emailAddress: "luke@skywalker.com", password: "obiwan") - customApp = try TestDataBuilder.getOAuth2Application( + app.shutdown() + app = try TestDataBuilder.getOAuth2Application( tokenManager: fakeTokenManager, clientRetriever: fakeClientGetter, authorizeHandler: capturingAuthHandler, @@ -361,7 +360,7 @@ class ImplicitGrantTests: XCTestCase { registeredUsers: [user] ) - _ = try await getImplicitGrantResponse(user: user, on: customApp!) + _ = try await getImplicitGrantResponse(user: user) guard let token = fakeTokenManager.getAccessToken(accessToken) else { XCTFail() @@ -385,7 +384,8 @@ class ImplicitGrantTests: XCTestCase { } func testThatUserMustBeLoggedInWhenMakingImplicitTokenRequest() async throws { - customApp = try TestDataBuilder.getOAuth2Application( + app.shutdown() + app = try TestDataBuilder.getOAuth2Application( tokenManager: fakeTokenManager, clientRetriever: fakeClientGetter, authorizeHandler: capturingAuthHandler, @@ -393,7 +393,7 @@ class ImplicitGrantTests: XCTestCase { sessions: fakeSessions ) - let response = try await getImplicitGrantResponse(user: nil, on: customApp!) + let response = try await getImplicitGrantResponse(user: nil) XCTAssertEqual(response.status, .unauthorized) } @@ -466,18 +466,9 @@ class ImplicitGrantTests: XCTestCase { clientID: String? = "ABCDEF", redirectURI: String? = "https://api.brokenhands.io/callback", scope: String? = nil, - state: String? = nil, - on customApp: Application? = nil + state: String? = nil ) async throws -> XCTHTTPResponse { - let app: Application! = customApp ?? self.app - return try await TestDataBuilder.getAuthRequestResponse( - with: app, - responseType: responseType, - clientID: clientID, - redirectURI: redirectURI, - scope: scope, - state: state - ) + return try await TestDataBuilder.getAuthRequestResponse(with: app, responseType: responseType, clientID: clientID, redirectURI: redirectURI, scope: scope, state: state) } private func getImplicitGrantResponse( @@ -489,10 +480,8 @@ class ImplicitGrantTests: XCTestCase { state: String? = nil, user: OAuthUser? = TestDataBuilder.anyOAuthUser(), csrfToken: String? = "the-csrf-token", - sessionID: String? = "the-session-ID", - on customApp: Application? = nil + sessionID: String? = "the-session-ID" ) async throws -> XCTHTTPResponse { - let app: Application! = customApp ?? self.app return try await TestDataBuilder.getAuthResponseResponse( with: app, approve: approve,