From 99eefa07e81d478ff2cb3ec9108760054415317c Mon Sep 17 00:00:00 2001 From: Hernan Zalazar Date: Mon, 21 Mar 2016 22:51:39 -0300 Subject: [PATCH] Avoid overriding connection name for social login --- Lock/Core/A0APIClient.m | 2 +- Lock/UI/NIBs/A0SignUpViewController.xib | 20 +-------- LockTests/A0APIClientSpec.swift | 55 +++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/Lock/Core/A0APIClient.m b/Lock/Core/A0APIClient.m index a0a661b19..440948395 100644 --- a/Lock/Core/A0APIClient.m +++ b/Lock/Core/A0APIClient.m @@ -349,7 +349,6 @@ - (NSURLSessionDataTask *)authenticateWithSocialConnectionName:(NSString *)conne failure:(A0APIClientError)failure { NSDictionary *params = @{ kClientIdParamName: self.clientId, - kConnectionParamName: connectionName, }; A0AuthParameters *defaultParameters = [A0AuthParameters newWithDictionary:params]; if (credentials.extraInfo[A0StrategySocialTokenSecretParameter]) { @@ -363,6 +362,7 @@ - (NSURLSessionDataTask *)authenticateWithSocialConnectionName:(NSString *)conne defaultParameters[A0ParameterMainAccessToken] = defaultParameters.accessToken; } defaultParameters.accessToken = credentials.accessToken; + defaultParameters[kConnectionParamName] = connectionName; NSDictionary *payload = [defaultParameters asAPIPayload]; A0LogVerbose(@"Authenticating with social strategy %@ and payload %@", connectionName, payload); diff --git a/Lock/UI/NIBs/A0SignUpViewController.xib b/Lock/UI/NIBs/A0SignUpViewController.xib index 146725ac7..c27e6e69e 100644 --- a/Lock/UI/NIBs/A0SignUpViewController.xib +++ b/Lock/UI/NIBs/A0SignUpViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -25,7 +25,6 @@ - @@ -196,10 +182,8 @@ - - diff --git a/LockTests/A0APIClientSpec.swift b/LockTests/A0APIClientSpec.swift index e0d707185..8f59e1460 100644 --- a/LockTests/A0APIClientSpec.swift +++ b/LockTests/A0APIClientSpec.swift @@ -440,6 +440,43 @@ class A0APIClientSpec : QuickSpec { }) } } + + it("should request change password") { + api.allowChangePasswordWithParameters([ + "email": EMAIL, + "connection": DB_CONNECTION + ]) + waitUntil { done in + client.requestChangePasswordForUsername(EMAIL, + parameters: nil, + success: { done() }, + failure: { _ in + fail("Should have changed password") + done() + }) + } + } + + it("should fail to request change password with error") { + api.failForRoute(.ChangePassword, + parameters: [ + "email": EMAIL, + "connection": DB_CONNECTION + ], message: "failed_change_passsword") + waitUntil { done in + client.requestChangePasswordForUsername(EMAIL, + parameters: nil, + success: { + fail("Should have failed to change password") + done() + }, + failure: { error in + expect(error.localizedDescription).to(equal("failed_change_passsword")) + done() + }) + } + } + } describe("login with JWT") { @@ -656,6 +693,24 @@ class A0APIClientSpec : QuickSpec { } } + it("should not override connection name specified as a method parameter") { + api.allowSocialLoginWithParameters([ + "access_token": SOCIAL_TOKEN, + "connection": "facebook", + "scope": "openid offline_access" + ]) + api.allowTokenInfoForToken(JWT) + let parameters = A0AuthParameters.newDefaultParams() + parameters["connection"] = "invalid connection" + waitUntil { done in + client.authenticateWithSocialConnectionName("facebook", + credentials: credentials, + parameters: parameters, + success: {_, _ in done() }, + failure: {_ in fail("Should not have failed")}) + } + } + it("should login with access token in parameters") { let parameters = A0AuthParameters.newDefaultParams() let accessToken = "AnotherToken"