Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisabhash committed Dec 4, 2023
1 parent f8a795a commit f18554b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class AWSAuthPasswordlessClient : AuthPasswordlessBehavior {
throw AuthError.unknown("Response received is not a HTTPURLResponse")
}

if response.statusCode == 200 {
switch response.statusCode {
case 200..<300:
return
} else {
default:
throw AuthError.unknown("Response received with status code: \(response.statusCode)")
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
/// - I should get the info in next step
///
func testSignInWithMagicLink() async {

let username = "username"
let redirectURL = "https://example.com/magic-link/##code##"
setUpWith(authPasswordlessEnvironment:
BasicPasswordlessEnvironment(authPasswordlessFactory: makeAuthPasswordlessClient))
let clientMetadata = [
Expand All @@ -50,6 +51,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.signInMethod"], "MAGIC_LINK")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.action"], "REQUEST")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.deliveryMedium"], "EMAIL")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.redirectUri"], redirectURL)
XCTAssertEqual(input.clientMetadata?["somekey"], "somevalue")

return RespondToAuthChallengeOutput(
Expand All @@ -68,9 +70,9 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
let options = AuthSignInWithMagicLinkRequest.Options(pluginOptions: pluginOptions)
do {
let result = try await plugin.signInWithMagicLink(
username: "username",
username: username,
flow: .signIn,
redirectURL: "https://example.com/magic-link/##code##",
redirectURL: redirectURL,
options: options)

guard case .confirmSignInWithMagicLink(let codeDeliveryDetails, _) = result.nextStep else {
Expand Down Expand Up @@ -108,6 +110,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
///
func testSignUpAndSignInWithMagicLink() async {
let username = "username"
let redirectURL = "https://example.com/magic-link/##code##"
self.mockAuthPasswordlessProvider = MockAuthPasswordlessBehavior(mockGetAuthPasswordlessResponse: { url, payload in
XCTAssertEqual(url.absoluteString, Defaults.passwordlessSignUpEndpoint)
XCTAssertEqual(payload.username, username)
Expand Down Expand Up @@ -139,6 +142,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.signInMethod"], "MAGIC_LINK")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.action"], "REQUEST")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.deliveryMedium"], "EMAIL")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.redirectUri"], redirectURL)
XCTAssertEqual(input.clientMetadata?["somekey"], "somevalue")

return RespondToAuthChallengeOutput(
Expand All @@ -160,7 +164,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
let result = try await plugin.signInWithMagicLink(
username: username,
flow: .signUpAndSignIn,
redirectURL: "https://example.com/magic-link/##code##",
redirectURL: redirectURL,
options: options)


Expand Down Expand Up @@ -199,6 +203,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
///
func testSignUpAndSignInWithMagicLinkWithMissingEndpointURL() async {
let username = "username"
let redirectURL = "https://example.com/magic-link/##code##"
self.mockAuthPasswordlessProvider = MockAuthPasswordlessBehavior(mockGetAuthPasswordlessResponse: { url, payload in
XCTAssertEqual(url.absoluteString, Defaults.passwordlessSignUpEndpoint)
XCTAssertEqual(payload.username, username)
Expand Down Expand Up @@ -235,6 +240,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.signInMethod"], "MAGIC_LINK")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.action"], "REQUEST")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.deliveryMedium"], "EMAIL")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.redirectUri"], redirectURL)
XCTAssertEqual(input.clientMetadata?["somekey"], "somevalue")

return RespondToAuthChallengeOutput(
Expand All @@ -256,7 +262,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
let _ = try await plugin.signInWithMagicLink(
username: username,
flow: .signUpAndSignIn,
redirectURL: "https://example.com/magic-link/##code##",
redirectURL: redirectURL,
options: options)

XCTFail("Should fail due to missing endpoint URL in configuration")
Expand Down Expand Up @@ -288,6 +294,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
///
func testSignUpAndSignInWithMagicLinkWithNilPasswordlessClient() async {
let username = "username"
let redirectURL = "https://example.com/magic-link/##code##"
self.mockAuthPasswordlessProvider = MockAuthPasswordlessBehavior(mockGetAuthPasswordlessResponse: { url, payload in
XCTAssertEqual(url.absoluteString, Defaults.passwordlessSignUpEndpoint)
XCTAssertEqual(payload.username, username)
Expand Down Expand Up @@ -317,6 +324,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.signInMethod"], "MAGIC_LINK")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.action"], "REQUEST")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.deliveryMedium"], "EMAIL")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.redirectUri"], redirectURL)
XCTAssertEqual(input.clientMetadata?["somekey"], "somevalue")

return RespondToAuthChallengeOutput(
Expand All @@ -338,7 +346,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
let _ = try await plugin.signInWithMagicLink(
username: username,
flow: .signUpAndSignIn,
redirectURL: "https://example.com/magic-link/##code##",
redirectURL: redirectURL,
options: options)

XCTFail("Should fail")
Expand Down Expand Up @@ -370,6 +378,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
///
func testSignUpAndSignInWithMagicLinkWithMissingUserPoolConfig() async {
let username = "username"
let redirectURL = "https://example.com/magic-link/##code##"
self.mockAuthPasswordlessProvider = MockAuthPasswordlessBehavior(mockGetAuthPasswordlessResponse: { url, payload in
XCTAssertEqual(url.absoluteString, Defaults.passwordlessSignUpEndpoint)
XCTAssertEqual(payload.username, username)
Expand Down Expand Up @@ -399,6 +408,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.signInMethod"], "MAGIC_LINK")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.action"], "REQUEST")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.deliveryMedium"], "EMAIL")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.redirectUri"], redirectURL)
XCTAssertEqual(input.clientMetadata?["somekey"], "somevalue")

return RespondToAuthChallengeOutput(
Expand All @@ -420,7 +430,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
let _ = try await plugin.signInWithMagicLink(
username: username,
flow: .signUpAndSignIn,
redirectURL: "https://example.com/magic-link/##code##",
redirectURL: redirectURL,
options: options)

XCTFail("Should fail")
Expand Down Expand Up @@ -452,6 +462,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
///
func testSignUpAndSignInWithMagicLinkWithEmptyEndpointURL() async {
let username = "username"
let redirectURL = "https://example.com/magic-link/##code##"
self.mockAuthPasswordlessProvider = MockAuthPasswordlessBehavior(mockGetAuthPasswordlessResponse: { url, payload in
XCTAssertEqual(url.absoluteString, Defaults.passwordlessSignUpEndpoint)
XCTAssertEqual(payload.username, username)
Expand Down Expand Up @@ -486,6 +497,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.signInMethod"], "MAGIC_LINK")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.action"], "REQUEST")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.deliveryMedium"], "EMAIL")
XCTAssertEqual(input.clientMetadata?["Amplify.Passwordless.redirectUri"], redirectURL)
XCTAssertEqual(input.clientMetadata?["somekey"], "somevalue")

return RespondToAuthChallengeOutput(
Expand All @@ -507,7 +519,7 @@ class AWSAuthSignInWithMagicLinkTaskTests: BasePluginTest {
let _ = try await plugin.signInWithMagicLink(
username: username,
flow: .signUpAndSignIn,
redirectURL: "https://example.com/magic-link/##code##",
redirectURL: redirectURL,
options: options)

XCTFail("Should fail due to missing endpoint URL in configuration")
Expand Down

0 comments on commit f18554b

Please sign in to comment.