Skip to content

Commit

Permalink
try ci fix
Browse files Browse the repository at this point in the history
  • Loading branch information
marius-se committed May 29, 2023
1 parent c5ebee0 commit c013cd0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
Expand Up @@ -6,6 +6,8 @@ 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 @@ -33,6 +35,7 @@ class AuthorizationRequestTests: XCTestCase {

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

Expand Down Expand Up @@ -221,8 +224,7 @@ class AuthorizationRequestTests: XCTestCase {
}

func testThatUnknownScopeReturnsInvalidScopeError() async throws {
app.shutdown()
app = try TestDataBuilder.getOAuth2Application(
customApp = try TestDataBuilder.getOAuth2Application(
clientRetriever: fakeClientRetriever,
authorizeHandler: capturingAuthoriseHandler,
validScopes: ["email", "profile", "admin"]
Expand All @@ -232,7 +234,8 @@ class AuthorizationRequestTests: XCTestCase {
let response = try await respondToOAuthRequest(
clientID: clientID,
redirectURI: redirectURI,
scope: invalidScope
scope: invalidScope,
on: customApp!
)

XCTAssertEqual(response.status, .seeOther)
Expand Down Expand Up @@ -292,8 +295,7 @@ class AuthorizationRequestTests: XCTestCase {
}

func testNonHTTPSRedirectURICanNotBeUsedWhenInProduction() async throws {
app.shutdown()
app = try TestDataBuilder.getOAuth2Application(
customApp = try TestDataBuilder.getOAuth2Application(
clientRetriever: fakeClientRetriever,
authorizeHandler: capturingAuthoriseHandler,
environment: .production
Expand All @@ -307,7 +309,7 @@ class AuthorizationRequestTests: XCTestCase {
)
fakeClientRetriever.validClients[clientID] = httpClient

_ = try await respondToOAuthRequest(clientID: clientID, redirectURI: nonHTTPSRedirectURI)
_ = try await respondToOAuthRequest(clientID: clientID, redirectURI: nonHTTPSRedirectURI, on: customApp!)

XCTAssertEqual(capturingAuthoriseHandler.authorizationError, .httpRedirectURI)
}
Expand Down Expand Up @@ -370,9 +372,11 @@ class AuthorizationRequestTests: XCTestCase {
clientID: String?,
redirectURI: String?,
scope: String? = nil,
state: String? = nil
state: String? = nil,
on customApp: Application? = nil
) async throws -> XCTHTTPResponse {
try await TestDataBuilder.getAuthRequestResponse(
let app: Application! = customApp ?? self.app
return try await TestDataBuilder.getAuthRequestResponse(
with: app,
responseType: responseType,
clientID: clientID,
Expand Down
Expand Up @@ -6,6 +6,7 @@ class AuthorizationResponseTests: XCTestCase {
// MARK: - Properties

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

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

Expand Down Expand Up @@ -128,9 +130,7 @@ class AuthorizationResponseTests: XCTestCase {
}

func testThatRedirectURIMustBeHTTPSForProduction() async throws {
app.shutdown()

app = try TestDataBuilder.getOAuth2Application(
customApp = 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)
let response = try await getAuthResponse(clientID: clientID, redirectURI: redirectURI, on: customApp!)

XCTAssertEqual(response.status, .badRequest)
}
Expand Down Expand Up @@ -308,9 +308,11 @@ class AuthorizationResponseTests: XCTestCase {
state: String? = nil,
user: OAuthUser? = TestDataBuilder.anyOAuthUser(),
csrfToken: String? = "the-csrf-token",
sessionID: String? = "the-session-ID"
sessionID: String? = "the-session-ID",
on customApp: Application? = nil
) async throws -> XCTHTTPResponse {
try await TestDataBuilder.getAuthResponseResponse(
let app: Application! = customApp ?? self.app
return try await TestDataBuilder.getAuthResponseResponse(
with: app,
approve: approve,
clientID: clientID,
Expand Down
35 changes: 23 additions & 12 deletions Tests/VaporOAuthTests/GrantTests/ImplicitGrantTests.swift
Expand Up @@ -4,6 +4,8 @@ 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 @@ -49,6 +51,7 @@ class ImplicitGrantTests: XCTestCase {

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

Expand Down Expand Up @@ -242,8 +245,7 @@ class ImplicitGrantTests: XCTestCase {
}

func testThatRedirectURIMustBeHTTPSForProduction() async throws {
app.shutdown()
app = try TestDataBuilder.getOAuth2Application(
customApp = try TestDataBuilder.getOAuth2Application(
clientRetriever: fakeClientGetter,
authorizeHandler: capturingAuthHandler,
environment: .production,
Expand All @@ -255,7 +257,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)
let response = try await getImplicitGrantResponse(clientID: clientID, redirectURI: redirectURI, on: customApp!)

XCTAssertEqual(response.status, .badRequest)
}
Expand Down Expand Up @@ -350,8 +352,7 @@ class ImplicitGrantTests: XCTestCase {
fakeTokenManager.accessTokenToReturn = accessToken
let user = OAuthUser(userID: userID, username: "luke", emailAddress: "luke@skywalker.com", password: "obiwan")

app.shutdown()
app = try TestDataBuilder.getOAuth2Application(
customApp = try TestDataBuilder.getOAuth2Application(
tokenManager: fakeTokenManager,
clientRetriever: fakeClientGetter,
authorizeHandler: capturingAuthHandler,
Expand All @@ -360,7 +361,7 @@ class ImplicitGrantTests: XCTestCase {
registeredUsers: [user]
)

_ = try await getImplicitGrantResponse(user: user)
_ = try await getImplicitGrantResponse(user: user, on: customApp!)

guard let token = fakeTokenManager.getAccessToken(accessToken) else {
XCTFail()
Expand All @@ -384,16 +385,15 @@ class ImplicitGrantTests: XCTestCase {
}

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

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

XCTAssertEqual(response.status, .unauthorized)
}
Expand Down Expand Up @@ -466,9 +466,18 @@ class ImplicitGrantTests: XCTestCase {
clientID: String? = "ABCDEF",
redirectURI: String? = "https://api.brokenhands.io/callback",
scope: String? = nil,
state: String? = nil
state: String? = nil,
on customApp: Application? = nil
) async throws -> XCTHTTPResponse {
return try await TestDataBuilder.getAuthRequestResponse(with: app, responseType: responseType, clientID: clientID, redirectURI: redirectURI, scope: scope, state: state)
let app: Application! = customApp ?? self.app
return try await TestDataBuilder.getAuthRequestResponse(
with: app,
responseType: responseType,
clientID: clientID,
redirectURI: redirectURI,
scope: scope,
state: state
)
}

private func getImplicitGrantResponse(
Expand All @@ -480,8 +489,10 @@ class ImplicitGrantTests: XCTestCase {
state: String? = nil,
user: OAuthUser? = TestDataBuilder.anyOAuthUser(),
csrfToken: String? = "the-csrf-token",
sessionID: String? = "the-session-ID"
sessionID: String? = "the-session-ID",
on customApp: Application? = nil
) async throws -> XCTHTTPResponse {
let app: Application! = customApp ?? self.app
return try await TestDataBuilder.getAuthResponseResponse(
with: app,
approve: approve,
Expand Down

0 comments on commit c013cd0

Please sign in to comment.