Skip to content

Commit

Permalink
Revert "try ci fix"
Browse files Browse the repository at this point in the history
This reverts commit c013cd0.
  • Loading branch information
marius-se committed May 29, 2023
1 parent c013cd0 commit e25096c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 43 deletions.
Expand Up @@ -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!

Expand Down Expand Up @@ -35,7 +33,6 @@ class AuthorizationRequestTests: XCTestCase {

override func tearDown() async throws {
app.shutdown()
customApp?.shutdown()
try await super.tearDown()
}

Expand Down Expand Up @@ -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"]
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down
Expand Up @@ -6,7 +6,6 @@ class AuthorizationResponseTests: XCTestCase {
// MARK: - Properties

var app: Application!
var customApp: Application?
var fakeClientRetriever: FakeClientGetter!
var capturingAuthoriseHandler: CapturingAuthoriseHandler!
var fakeCodeManager: FakeCodeManager!
Expand Down Expand Up @@ -50,7 +49,6 @@ class AuthorizationResponseTests: XCTestCase {

override func tearDown() async throws {
app.shutdown()
customApp?.shutdown()
try await super.tearDown()
}

Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down
35 changes: 12 additions & 23 deletions Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift
Expand Up @@ -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!
Expand Down Expand Up @@ -51,7 +49,6 @@ class ImplicitGrantTests: XCTestCase {

override func tearDown() async throws {
app.shutdown()
customApp?.shutdown()
try await super.tearDown()
}

Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -385,15 +384,16 @@ class ImplicitGrantTests: XCTestCase {
}

func testThatUserMustBeLoggedInWhenMakingImplicitTokenRequest() async throws {
customApp = try TestDataBuilder.getOAuth2Application(
app.shutdown()
app = try TestDataBuilder.getOAuth2Application(
tokenManager: fakeTokenManager,
clientRetriever: fakeClientGetter,
authorizeHandler: capturingAuthHandler,
validScopes: [scope1, scope2, scope3],
sessions: fakeSessions
)

let response = try await getImplicitGrantResponse(user: nil, on: customApp!)
let response = try await getImplicitGrantResponse(user: nil)

XCTAssertEqual(response.status, .unauthorized)
}
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit e25096c

Please sign in to comment.