Skip to content

Commit

Permalink
Issue 168: OktaOidcMetadataDiscovery.run() doesn't surface errors gen…
Browse files Browse the repository at this point in the history
…erated by OIDServiceDiscovery initializer

#168
  • Loading branch information
IldarAbdullin-okta committed Jul 12, 2019
1 parent 4d83ed5 commit 67ce89e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 20 deletions.
44 changes: 44 additions & 0 deletions Tests/OktaOidcConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,50 @@ class OktaOidcConfigTests: XCTestCase {
XCTAssertEqual(1, config.additionalParams?.count)
XCTAssertEqual("test_param", config.additionalParams?["additionalParam"])
}

func testCreationWithInvalidConfig() {
var dict = [
"clientId" : "test_client_id",
"issuer" : "",
"scopes" : "test_scope",
"redirectUri" : "com.test:/callback"
]

do {
let _ = try OktaOidcConfig(with: dict)
} catch let error {
XCTAssertTrue(error.localizedDescription == OktaOidcError.missingConfigurationValues.errorDescription)
return
}

dict = [
"clientId" : "",
"issuer" : "http://www.test.com",
"scopes" : "test_scope",
"redirectUri" : "com.test:/callback"
]

do {
let _ = try OktaOidcConfig(with: dict)
} catch let error {
XCTAssertTrue(error.localizedDescription == OktaOidcError.missingConfigurationValues.errorDescription)
return
}

dict = [
"clientId" : "test_client_id",
"issuer" : "http://www.test.com",
"scopes" : "test_scope",
"redirectUri" : ""
]

do {
let _ = try OktaOidcConfig(with: dict)
} catch let error {
XCTAssertTrue(error.localizedDescription == OktaOidcError.missingConfigurationValues.errorDescription)
return
}
}

func testDefaultConfig() {
do {
Expand Down
20 changes: 0 additions & 20 deletions Tests/OktaOidcDiscoveryTaskTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,6 @@ class OktaOidcDiscoveryTaskTests: XCTestCase {
)
}
}

func testRunInvalidUrl() {
self.runAndWaitDiscovery(config: self.invalidConfig) { oidConfig, error in
XCTAssert(Thread.current.isMainThread)
XCTAssertNil(oidConfig)
XCTAssertEqual(
OktaOidcError.noDiscoveryEndpoint.localizedDescription,
error?.localizedDescription
)
}
}

func testRunDiscoveryEndpointURL() {
apiMock.configure(response: validOIDConfigDictionary) { request in
Expand Down Expand Up @@ -110,15 +99,6 @@ class OktaOidcDiscoveryTaskTests: XCTestCase {
"redirectUri" : "test:/callback"
])
}

private var invalidConfig: OktaOidcConfig {
return try! OktaOidcConfig(with: [
"issuer" : " ",
"clientId" : "test_client",
"scopes" : "test",
"redirectUri" : "test:/callback"
])
}

private var validOIDConfigDictionary: [String:Any] {
return [
Expand Down

0 comments on commit 67ce89e

Please sign in to comment.