Skip to content

Commit

Permalink
Merge pull request #165 from ibm-cloud-security/ibm-cloud-rebranding
Browse files Browse the repository at this point in the history
cloud.ibm.com rebranding
  • Loading branch information
vitalymibm committed Dec 12, 2018
2 parents b969aa7 + f35a35a commit 65e4d1d
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: objective-c
matrix:
include:
- osx_image: xcode9.4
- osx_image: xcode10
install:
- gem install jazzy
- gem install slather -v 2.4.5
Expand Down
2 changes: 0 additions & 2 deletions IBMCloudAppID.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
EFBA20661E51F7D9000EB3F5 /* IdentityTokenImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFBA20131E51F7D9000EB3F5 /* IdentityTokenImpl.swift */; };
EFBA20681E51F7D9000EB3F5 /* OAuthClientImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFBA20141E51F7D9000EB3F5 /* OAuthClientImpl.swift */; };
EFBA206A1E51F7D9000EB3F5 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFBA20151E51F7D9000EB3F5 /* Utils.swift */; };
EFBA206D1E51F7D9000EB3F5 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = EFBA20161E51F7D9000EB3F5 /* Info.plist */; };
EFBBC76B1DF99BF6000CE39A /* IBMCloudAppID.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EFBBC7541DF99AFA000CE39A /* IBMCloudAppID.framework */; };
EFD0251B1E55FC8D00AE1803 /* IBMCloudAppID.h in Headers */ = {isa = PBXBuildFile; fileRef = EFD0251A1E55FC8D00AE1803 /* IBMCloudAppID.h */; settings = {ATTRIBUTES = (Public, ); }; };
EFE8DC1D1DFDAE920039A5F2 /* BMSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EFE8DC1C1DFDAE920039A5F2 /* BMSCore.framework */; };
Expand Down Expand Up @@ -517,7 +516,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EFBA206D1E51F7D9000EB3F5 /* Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
12 changes: 6 additions & 6 deletions IBMCloudAppIDTests/AuthorizationManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public class AuthorizationManagerTests : XCTestCase {

func testLaunchChangePassword_success() {
let oAuthManager = OAuthManager(appId: AppID.sharedInstance)
AppID.sharedInstance.initialize(tenantId: "tenant1", region: "region2")
AppID.sharedInstance.initialize(tenantId: "tenant1", region: "https://region2")
let authManager = IBMCloudAppID.AuthorizationManager(oAuthManager: oAuthManager)

class delegate: AuthorizationDelegate {
Expand Down Expand Up @@ -293,13 +293,13 @@ public class AuthorizationManagerTests : XCTestCase {
oAuthManager.tokenManager = tokenManager
authManager.launchChangePasswordUI(authorizationDelegate:delegate(res:"", expectedErr:""))
XCTAssertEqual(authManager.authorizationUIManager?.redirectUri as String!, "redirect")
let expectedUrl: String! = "https://appid-oauthregion2/oauth/v3/tenant1/cloud_directory/change_password?user_id=bd98e7a8-6035-4e07-9d94-04c04c9fd7ab&client_id=someclient&redirect_uri=redirect&language=" + Locale.current.identifier
let expectedUrl: String! = "https://region2/oauth/v3/tenant1/cloud_directory/change_password?user_id=bd98e7a8-6035-4e07-9d94-04c04c9fd7ab&client_id=someclient&redirect_uri=redirect&language=" + Locale.current.identifier
XCTAssertEqual(authManager.authorizationUIManager?.authorizationUrl as String!, expectedUrl)
}

func tests_launchDetails() {
let oAuthManager = OAuthManager(appId: AppID.sharedInstance)
AppID.sharedInstance.initialize(tenantId: "tenant1", region: "region2")
AppID.sharedInstance.initialize(tenantId: "tenant1", region: "https://region2")
let authManager = MockAuthorizationManagerWithGoodResponse(oAuthManager: oAuthManager)
let authManagerNoCode = MockAuthorizationManager(oAuthManager: oAuthManager)
let authManagerRequestError = MockAuthorizationManagerWithRequestError(oAuthManager: oAuthManager)
Expand Down Expand Up @@ -357,7 +357,7 @@ public class AuthorizationManagerTests : XCTestCase {
func testLaunchChangeDetails_success(authManager: IBMCloudAppID.AuthorizationManager, delegate: AuthorizationDelegate) {
authManager.launchChangeDetailsUI(authorizationDelegate:delegate)
XCTAssertEqual(authManager.authorizationUIManager?.redirectUri as String!, "redirect")
let expectedUrl: String! = "https://appid-oauthregion2/oauth/v3/tenant1/cloud_directory/change_details?code=1234&client_id=someclient&redirect_uri=redirect&language=" + Locale.current.identifier
let expectedUrl: String! = "https://region2/oauth/v3/tenant1/cloud_directory/change_details?code=1234&client_id=someclient&redirect_uri=redirect&language=" + Locale.current.identifier
XCTAssertEqual(authManager.authorizationUIManager?.authorizationUrl as String!, expectedUrl)
}

Expand Down Expand Up @@ -516,12 +516,12 @@ public class AuthorizationManagerTests : XCTestCase {

}

AppID.sharedInstance.initialize(tenantId: "tenant1", region: ".region2")
AppID.sharedInstance.initialize(tenantId: "tenant1", region: "https://region2")
MockRegistrationManager.shouldFail = false
authManager.registrationManager = MockRegistrationManager(oauthManager:OAuthManager(appId:AppID.sharedInstance))
authManager.launchForgotPasswordUI(authorizationDelegate: delegate(res: "failure", expectedErr: ""))

let expectedUrl: String! = "https://appid-oauth.region2/oauth/v3/tenant1/cloud_directory/forgot_password?client_id=someclient&redirect_uri=redirect&language=" + Locale.current.identifier
let expectedUrl: String! = "https://region2/oauth/v3/tenant1/cloud_directory/forgot_password?client_id=someclient&redirect_uri=redirect&language=" + Locale.current.identifier
XCTAssertEqual(authManager.authorizationUIManager?.authorizationUrl as String!, expectedUrl)

}
Expand Down
8 changes: 4 additions & 4 deletions IBMCloudAppIDTests/ConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class ConfigTests: XCTestCase {
XCTAssertEqual("https://appid-oauth", Config.getServerUrl(appId: appid))

// with region and tenant
appid.initialize(tenantId: "sometenant", region: ".region")
XCTAssertEqual("https://appid-oauth.region/oauth/v3/sometenant", Config.getServerUrl(appId: appid))
appid.initialize(tenantId: "sometenant", region: "https://region")
XCTAssertEqual("https://region/oauth/v3/sometenant", Config.getServerUrl(appId: appid))

XCTAssertEqual("https://appid-oauth.region/oauth/v3/sometenant/publickeys", Config.getPublicKeyEndpoint(appId: appid))
XCTAssertEqual("https://region/oauth/v3/sometenant/publickeys", Config.getPublicKeyEndpoint(appId: appid))

XCTAssertEqual("appid-oauth.region", Config.getIssuer(appId: appid))
XCTAssertEqual("region", Config.getIssuer(appId: appid))

// with overrideserverhost
AppID.overrideServerHost = "somehost/"
Expand Down
9 changes: 5 additions & 4 deletions IBMCloudAppIDTests/RegistrationManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ public class RegistrationManagerTests: XCTestCase {

XCTAssertEqual(request.resourceUrl, Config.getServerUrl(appId: AppID.sharedInstance) + "/clients")
XCTAssertEqual(request.httpMethod, HttpMethod.POST)
XCTAssertEqual(request.headers, [Request.contentType : "application/json"])
XCTAssertEqual(request.headers, [Request.contentType : "application/json"])
XCTAssertEqual(request.timeout, BMSClient.sharedInstance.requestTimeout)
let dataAsDictionary = try? Utils.parseJsonStringtoDictionary(String(data: registrationParamsAsData!, encoding: .utf8)!)
XCTAssertEqual(try? Utils.JSONStringify(dataAsDictionary as AnyObject), "{\"token_endpoint_auth_method\":\"client_secret_basic\",\"device_model\":\"iPhone\",\"software_version\":\"1.0\",\"client_type\":\"mobileapp\",\"device_os\":\"iOS\",\"software_id\":\"oded.dummyAppForKeyChain\",\"grant_types\":[\"authorization_code\",\"password\"],\"jwks\":{\"keys\":[{\"e\":\"AQAB\",\"kty\":\"RSA\",\"n\":\"AOH-nACU3cCopAz6_SzJuDtUyN4nHhnk9yfF9DFiGPctXPbwMXofZvd9WcYQqtw-w3WV_yhui9PrOVfVBhk6CmM=\"}]},\"redirect_uris\":[\"oded.dummyAppForKeyChain:\\/\\/mobile\\/callback\"],\"device_id\":\"" + (UIDevice.current.identifierForVendor?.uuidString)! + "\",\"response_types\":[\"code\"],\"device_os_version\":\"" + UIDevice.current.systemVersion + "\"}")

let expectedString = "{\"token_endpoint_auth_method\":\"client_secret_basic\",\"device_model\":\"iPhone\",\"software_version\":\"1.0\",\"client_type\":\"mobileapp\",\"device_os\":\"iOS\",\"software_id\":\"oded.dummyAppForKeyChain\",\"grant_types\":[\"authorization_code\",\"password\"],\"jwks\":{\"keys\":[{\"e\":\"AQAB\",\"kty\":\"RSA\",\"n\":\"AOH-nACU3cCopAz6_SzJuDtUyN4nHhnk9yfF9DFiGPctXPbwMXofZvd9WcYQqtw-w3WV_yhui9PrOVfVBhk6CmM=\"}]},\"redirect_uris\":[\"oded.dummyAppForKeyChain:\\/\\/mobile\\/callback\"],\"device_id\":\"" + (UIDevice.current.identifierForVendor?.uuidString)! + "\",\"response_types\":[\"code\"],\"device_os_version\":\"" + UIDevice.current.systemVersion + "\"}"
let actual = try! Utils.parseJsonStringtoDictionary(String(data: registrationParamsAsData!, encoding: .utf8)!)
let expected = try! Utils.parseJsonStringtoDictionary(expectedString)
XCTAssertTrue(NSDictionary(dictionary: actual).isEqual(to: expected))
internalCallBack(response, err)
}

Expand Down
6 changes: 6 additions & 0 deletions IBMCloudAppIDTests/TestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public class TestHelpers {
}
}

public static func validateFormData(expected: String, found: String) -> Void {
let expParamsSet = Set(expected.split(separator: "&").map { String($0) })
let fndParamsSet = Set(found.split(separator: "&").map { String($0) })
XCTAssertFalse(expParamsSet.isDisjoint(with: fndParamsSet))
}

public class MockTokenManager: TokenManager {
var shouldCallObtainWithRefresh = false
var obtainWithRefreshShouldFail = false
Expand Down
31 changes: 18 additions & 13 deletions IBMCloudAppIDTests/TokenManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ class TokenManagerTests: XCTestCase {
XCTAssertEqual(request.headers["Content-Type"], "application/x-www-form-urlencoded")
XCTAssertEqual(request.headers["Authorization"], "Bearer signature")
XCTAssertEqual(request.timeout, BMSClient.sharedInstance.requestTimeout)
XCTAssertEqual(String(data: registrationParamsAsData!, encoding: .utf8), "grant_type=authorization_code&code=thisisgrantcode&client_id=someclient&redirect_uri=redirect")

TestHelpers.validateFormData(
expected: "grant_type=authorization_code&code=thisisgrantcode&client_id=someclient&redirect_uri=redirect",
found: String(data: registrationParamsAsData!, encoding: .utf8)!)
internalCallBack(response, err)
}

Expand Down Expand Up @@ -122,8 +123,9 @@ class TokenManagerTests: XCTestCase {
XCTAssertEqual(request.headers["Content-Type"], "application/x-www-form-urlencoded")
XCTAssertEqual(request.headers["Authorization"], "Bearer signature")
XCTAssertEqual(request.timeout, BMSClient.sharedInstance.requestTimeout)
XCTAssertEqual(String(data: registrationParamsAsData!, encoding: .utf8), "grant_type=password&username=thisisusername&password=thisispassword")

TestHelpers.validateFormData(
expected: "grant_type=password&username=thisisusername&password=thisispassword",
found: String(data: registrationParamsAsData!, encoding: .utf8)!)
internalCallBack(response, err)
}

Expand Down Expand Up @@ -282,8 +284,9 @@ class TokenManagerTests: XCTestCase {
XCTFail("err: \(error)")
}
}
XCTAssertEqual(tokenManager.requestFormData,
"grant_type=password&appid_access_token=testAccessToken&username=thisisusername&password=thisispassword")
TestHelpers.validateFormData(
expected: tokenManager.requestFormData!,
found: "grant_type=password&appid_access_token=testAccessToken&username=thisisusername&password=thisispassword")
}

func testObtainTokensUsingRefreshToken() {
Expand All @@ -301,7 +304,9 @@ class TokenManagerTests: XCTestCase {
XCTFail("err: \(error)")
}
}
XCTAssertEqual(tokenManager.requestFormData, "refresh_token=xxtt&grant_type=refresh_token")
TestHelpers.validateFormData(
expected: tokenManager.requestFormData!,
found: "refresh_token=xxtt&grant_type=refresh_token")
}

func testObtainTokensUsingRop2_catch() {
Expand Down Expand Up @@ -698,12 +703,12 @@ class TokenManagerTests: XCTestCase {
return
}
let mockAppId = MockAppId.sharedInstance
mockAppId.initialize(tenantId: "4dba9430-54e6-4cf2-a516", region: ".ng.bluemix.net")
mockAppId.initialize(tenantId: "4dba9430-54e6-4cf2-a516", region: "https://us-south.appid.cloud.ibm.com")
let oauthManager = OAuthManager(appId: mockAppId)
oauthManager.registrationManager?.preferenceManager.getJSONPreference(name: AppIDConstants.registrationDataPref).set([AppIDConstants.client_id_String : AppIDTestConstants.clientId])

let manager:TokenManager = TokenManager(oAuthManager: OAuthManager(appId: mockAppId))
MockAppId.overrideServerHost = "https://app-oauth.ng.bluemix.net/oauth/v3/"
MockAppId.overrideServerHost = "https://us-south.appid.cloud.ibm.com/oauth/v3/"

manager.validateToken(token: validToken, key: key, tokenResponseDelegate: tokenRespDelegatIssuer) {tokenRespDelegatIssuer.onAuthorizationSuccess(accessToken: validToken,identityToken: nil,refreshToken: nil,response:response)}
XCTAssertEqual(tokenRespDelegatIssuer.success, 0)
Expand All @@ -727,11 +732,11 @@ class TokenManagerTests: XCTestCase {
}

let mockAppId = MockAppId.sharedInstance
mockAppId.initialize(tenantId: "4dba9430-54e6-4cf2-a516", region: ".ng.bluemix.net")
mockAppId.initialize(tenantId: "4dba9430-54e6-4cf2-a516", region: "https://us-south.appid.cloud.ibm.com")
let oauthManager = OAuthManager(appId: mockAppId)
oauthManager.registrationManager?.preferenceManager.getJSONPreference(name: AppIDConstants.registrationDataPref).set([AppIDConstants.client_id_String : "clientId"])
let manager:TokenManager = TokenManager(oAuthManager: oauthManager)
MockAppId.overrideServerHost = "https://appid-oauth.ng.bluemix.net/oauth/v3/"
MockAppId.overrideServerHost = "https://appid-oauth.ng.bluemix.net/"

manager.validateToken(token: validToken, key: key, tokenResponseDelegate: tokenRespDelegate) {tokenRespDelegate.onAuthorizationSuccess(accessToken: validToken,identityToken: nil,refreshToken: nil,response:response)}
XCTAssertEqual(tokenRespDelegate.success, 0)
Expand All @@ -757,11 +762,11 @@ class TokenManagerTests: XCTestCase {
}

let mockAppId = MockAppId.sharedInstance
mockAppId.initialize(tenantId: "4dba9430-54e6-4cf2-a516", region: ".ng.bluemix.net")
mockAppId.initialize(tenantId: "4dba9430-54e6-4cf2-a516", region: "https://appid-oauth.ng.bluemix.net")
let oauthManager = OAuthManager(appId: mockAppId)
oauthManager.registrationManager?.preferenceManager.getJSONPreference(name: AppIDConstants.registrationDataPref).set([AppIDConstants.client_id_String : AppIDTestConstants.clientId])
let manager:TokenManager = TokenManager(oAuthManager: OAuthManager(appId: mockAppId))
MockAppId.overrideServerHost = "https://appid-oauth.ng.bluemix.net/oauth/v3/"
MockAppId.overrideServerHost = "https://appid-oauth.ng.bluemix.net/"

manager.validateToken(token: validToken, key: key, tokenResponseDelegate: tokenRespDelegateTenant) {tokenRespDelegateTenant.onAuthorizationSuccess(accessToken: validToken,identityToken: nil,refreshToken: nil,response:response)}
XCTAssertEqual(tokenRespDelegateTenant.success, 0)
Expand Down
14 changes: 8 additions & 6 deletions Source/IBMCloudAppID/api/AppID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public class AppID {
public static var sharedInstance = AppID()
internal static let logger = Logger.logger(name: AppIDConstants.AppIDLoggerName)

static public let REGION_US_SOUTH = ".ng.bluemix.net"
static public let REGION_US_EAST = ".us-east.bluemix.net"
static public let REGION_UK = ".eu-gb.bluemix.net"
static public let REGION_SYDNEY = ".au-syd.bluemix.net"
static public let REGION_GERMANY = ".eu-de.bluemix.net"
static public let REGION_TOKYO = ".jp-tok.bluemix.net"
static public let REGION_US_SOUTH = "https://us-south.appid.cloud.ibm.com"
static public let REGION_US_SOUTH_STAGE1 = "https://us-south.appid.test.cloud.ibm.com"
static public let REGION_US_EAST = "https://us-east.appid.cloud.ibm.com"
static public let REGION_UK = "https://eu-gb.appid.cloud.ibm.com"
static public let REGION_UK_STAGE1 = "https://eu-gb.appid.test.cloud.ibm.com"
static public let REGION_SYDNEY = "https://au-syd.appid.cloud.ibm.com"
static public let REGION_GERMANY = "https://eu-de.appid.cloud.ibm.com"
static public let REGION_TOKYO = "https://jp-tok.appid.cloud.ibm.com"

internal init() {}

Expand Down
4 changes: 2 additions & 2 deletions Source/IBMCloudAppID/internal/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class Config {
return serverUrlPrefix
}

var serverUrl = Config.serverUrlPrefix + region + "/oauth/v3/"
var serverUrl = region + "/oauth/v3/"
if let overrideServerHost = AppID.overrideServerHost {
serverUrl = overrideServerHost
}
Expand All @@ -45,7 +45,7 @@ internal class Config {
return serverUrlPrefix
}

var attributesUrl = Config.attributesUrlPrefix + region + "/api/v1/"
var attributesUrl = region + "/api/v1/"
if let overrideHost = AppID.overrideAttributesHost {
attributesUrl = overrideHost
}
Expand Down

0 comments on commit 65e4d1d

Please sign in to comment.