Skip to content

Commit

Permalink
Rebrand, UserInfo, Swift 4 migration and token validation (#141)
Browse files Browse the repository at this point in the history
* Migrate to Swift 4

* Changes objective-c inference to default

* Validates tokens  (#137)

* sync development branch

* Add token validation

* fix spacing

* update deployment target

* remove trailing whitespace

* rebrand bluemix to ibm cloud (#140)

* rebrand bluemix to ibm cloud

* update gitignore file

* update readme

* udpate branding

* rename workspace to IBMCloudAppID

* Codacy Error Fix (#142)

* rebrand bluemix to ibm cloud

* update gitignore file

* update readme

* udpate branding

* rename workspace to IBMCloudAppID

* Codacy fix

* codacy fix
  • Loading branch information
ishangulhane authored and gtaban committed Jun 8, 2018
1 parent 2a9b4f9 commit 7a4978a
Show file tree
Hide file tree
Showing 69 changed files with 1,153 additions and 774 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BluemixAppID.xcodeproj/
BluemixAppID.xcworkspace/
IBMCloudAppID.xcodeproj/
IBMCloudAppID.xcworkspace/
Pods/
Podfile.lock
.idea/
*.DS_Store
*.DS_Store
8 changes: 4 additions & 4 deletions .slather.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
coverage_service: coveralls
workspace: BluemixAppID
xcodeproj: BluemixAppID.xcodeproj
scheme: BluemixAppIDTests
workspace: IBMCloudAppID
xcodeproj: IBMCloudAppID.xcodeproj
scheme: IBMCloudAppIDTests
ignore:
- BluemixAppIDTests/*
- IBMCloudAppIDTests/*
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
4.0
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ script:
# Test that the framework can be installed and built, and passes all unit tests
- travis_wait pod update
- pod lib lint --allow-warnings
- xcodebuild -workspace 'BluemixAppID.xcworkspace' -scheme 'BluemixAppID' clean build CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
- travis_retry xcodebuild -workspace 'BluemixAppID.xcworkspace' test -scheme 'BluemixAppIDTests' -destination 'platform=iOS Simulator,name=iPhone 6' -enableCodeCoverage YES
- slather coverage --coveralls --binary-basename BluemixAppID.framework -v
- xcodebuild -workspace 'IBMCloudAppID.xcworkspace' -scheme 'IBMCloudAppID' clean build CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO
- travis_retry xcodebuild -workspace 'IBMCloudAppID.xcworkspace' test -scheme 'IBMCloudAppIDTests' -destination 'platform=iOS Simulator,name=iPhone 6' -enableCodeCoverage YES
- slather coverage --coveralls --binary-basename IBMCloudAppID.framework -v
# When merging or pushing to the master branch, release a new version and publish the API documentation
#- if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_BRANCH}" = "master" ] ; then
# bash scripts/release.sh;
Expand Down
14 changes: 0 additions & 14 deletions BluemixAppID.podspec

This file was deleted.

Binary file not shown.
15 changes: 15 additions & 0 deletions IBMCloudAppID.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Pod::Spec.new do |s|
s.name = "IBMCloudAppID"
s.version = '4.0.0'
s.summary = "AppID Swift SDK"
s.homepage = "https://github.com/ibm-cloud-security/appid-clientsdk-swift"
s.license = 'Apache License, Version 2.0'
s.author = { "IBM Cloud Services Mobile SDK" => "[email protected]" }
s.swift_version = "4.0"
s.source = { :git => 'https://github.com/ibm-cloud-security/appid-clientsdk-swift.git', :tag => "#{s.version}" }
s.dependency 'BMSCore'
s.dependency 'JOSESwift'
s.requires_arc = true
s.source_files = 'Source/**/*.swift', 'Source/Resources/IBMCloudAppID.h'
s.ios.deployment_target = '10.0'
end

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -15,9 +15,9 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EFBBC7531DF99AFA000CE39A"
BuildableName = "BluemixAppID.framework"
BlueprintName = "BluemixAppID"
ReferencedContainer = "container:BluemixAppID.xcodeproj">
BuildableName = "IBMCloudAppID.framework"
BlueprintName = "IBMCloudAppID"
ReferencedContainer = "container:IBMCloudAppID.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand All @@ -26,27 +26,27 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EFBBC7651DF99BF6000CE39A"
BuildableName = "BluemixAppIDTests.xctest"
BlueprintName = "BluemixAppIDTests"
ReferencedContainer = "container:BluemixAppID.xcodeproj">
BuildableName = "IBMCloudAppIDTests.xctest"
BlueprintName = "IBMCloudAppIDTests"
ReferencedContainer = "container:IBMCloudAppID.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EFBBC7531DF99AFA000CE39A"
BuildableName = "BluemixAppID.framework"
BlueprintName = "BluemixAppID"
ReferencedContainer = "container:BluemixAppID.xcodeproj">
BuildableName = "IBMCloudAppID.framework"
BlueprintName = "IBMCloudAppID"
ReferencedContainer = "container:IBMCloudAppID.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
Expand All @@ -66,9 +66,9 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EFBBC7531DF99AFA000CE39A"
BuildableName = "BluemixAppID.framework"
BlueprintName = "BluemixAppID"
ReferencedContainer = "container:BluemixAppID.xcodeproj">
BuildableName = "IBMCloudAppID.framework"
BlueprintName = "IBMCloudAppID"
ReferencedContainer = "container:IBMCloudAppID.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
Expand All @@ -84,9 +84,9 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EFBBC7531DF99AFA000CE39A"
BuildableName = "BluemixAppID.framework"
BlueprintName = "BluemixAppID"
ReferencedContainer = "container:BluemixAppID.xcodeproj">
BuildableName = "IBMCloudAppID.framework"
BlueprintName = "IBMCloudAppID"
ReferencedContainer = "container:IBMCloudAppID.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
LastUpgradeVersion = "0930"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -10,17 +10,17 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "EFBBC7651DF99BF6000CE39A"
BuildableName = "BluemixAppIDTests.xctest"
BlueprintName = "BluemixAppIDTests"
ReferencedContainer = "container:BluemixAppID.xcodeproj">
BuildableName = "IBMCloudAppIDTests.xctest"
BlueprintName = "IBMCloudAppIDTests"
ReferencedContainer = "container:IBMCloudAppID.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,44 @@ import Foundation

import XCTest
import BMSCore
@testable import BluemixAppID
@testable import IBMCloudAppID

public class AppIDAuthorizationManagerTests: XCTestCase {

static var appid:AppID? = nil
static var manager:AppIDAuthorizationManager? = nil

override public func setUp() {
super.setUp()
AppID.sharedInstance.initialize(tenantId: "123", bluemixRegion: "123")
AppID.sharedInstance.initialize(tenantId: "123", region: "123")
AppIDAuthorizationManagerTests.appid = AppID.sharedInstance
AppIDAuthorizationManagerTests.manager = AppIDAuthorizationManager(appid: AppIDAuthorizationManagerTests.appid!)
}

public func testIsAuthorizationRequired () {

// 401 status, Www-Authenticate header exist, but invalid value
XCTAssertFalse((AppIDAuthorizationManagerTests.manager?.isAuthorizationRequired(for: 401, httpResponseAuthorizationHeader: "Dummy"))!)

// 401 status, Www-Authenticate header exists, Bearer exists, but not appid scope
XCTAssertFalse((AppIDAuthorizationManagerTests.manager?.isAuthorizationRequired(for: 401, httpResponseAuthorizationHeader: "Bearer Dummy"))!)

// 401 with bearer and correct scope
XCTAssertTrue((AppIDAuthorizationManagerTests.manager?.isAuthorizationRequired(for: 401, httpResponseAuthorizationHeader: "Bearer scope=\"appid_default\""))!)

// Check with http response

let response = HTTPURLResponse(url: URL(string: "ADS")!, statusCode: 401, httpVersion: nil, headerFields: [AppIDConstants.WWW_AUTHENTICATE_HEADER : "Bearer scope=\"appid_default\""])
XCTAssertTrue((AppIDAuthorizationManagerTests.manager?.isAuthorizationRequired(for: Response(responseData: nil, httpResponse: response, isRedirect: false)))!)
}

static var expectedResponse:Response = Response(responseData: nil, httpResponse: HTTPURLResponse(url: URL(string: "ADS")!, statusCode: 401, httpVersion: nil, headerFields: [AppIDConstants.WWW_AUTHENTICATE_HEADER : "Bearer scope=\"appid_default\""]), isRedirect: false)
class MockAuthorizationManager: BluemixAppID.AuthorizationManager {
class MockAuthorizationManager: IBMCloudAppID.AuthorizationManager {
static var res = "cancel"

var shouldCallObtainTokensRefreshToken = false
var obtainTokensRefreshTokenCalled = false

override func launchAuthorizationUI(accessTokenString: String? = nil, authorizationDelegate:AuthorizationDelegate) {
if MockAuthorizationManager.res == "success" {
authorizationDelegate.onAuthorizationSuccess(
Expand All @@ -64,34 +64,34 @@ public class AppIDAuthorizationManagerTests: XCTestCase {
} else {
authorizationDelegate.onAuthorizationCanceled()
}

}

override func signinWithRefreshToken(refreshTokenString: String?, tokenResponseDelegate: TokenResponseDelegate) {
obtainTokensRefreshTokenCalled = true
if !shouldCallObtainTokensRefreshToken {
XCTFail("Unexpected call to obtainTokensRefreshToken")
}
}

func verify() {
if shouldCallObtainTokensRefreshToken && !obtainTokensRefreshTokenCalled {
XCTFail("Should have called obtainTokensRefreshToken, but the function wasn't called")
}
}
}


public func testObtainAuthorizationCanceled() {

MockAuthorizationManager.res = "cancel"
AppIDAuthorizationManagerTests.manager?.oAuthManager.authorizationManager = MockAuthorizationManager(oAuthManager: (AppIDAuthorizationManagerTests.manager?.oAuthManager)!)
let callback:BMSCompletionHandler = {(response:Response?, error:Error?) in
XCTAssertNil(response)
XCTAssertEqual((error as? AuthorizationError)?.description, "Authorization canceled")
}
AppIDAuthorizationManagerTests.manager?.obtainAuthorization(completionHandler: callback)

}

public func testObtainAuthorizationSuccess() {
Expand All @@ -106,15 +106,15 @@ public class AppIDAuthorizationManagerTests: XCTestCase {
}
AppIDAuthorizationManagerTests.manager?.obtainAuthorization(completionHandler: callback)
}

public func testObtainAuthorizationWithRefreshTokenSuccess() {
MockAuthorizationManager.res = "failure"

AppIDAuthorizationManagerTests.manager?.oAuthManager.authorizationManager = MockAuthorizationManager(oAuthManager: (AppIDAuthorizationManagerTests.manager?.oAuthManager)!)

let tokenManager = TestHelpers.MockTokenManager(
oAuthManager: AppIDAuthorizationManagerTests.manager!.oAuthManager)

AppIDAuthorizationManagerTests.manager?.oAuthManager.tokenManager = tokenManager
tokenManager.latestRefreshToken = RefreshTokenImpl(with: "ststs")
tokenManager.shouldCallObtainWithRefresh = true
Expand All @@ -125,7 +125,7 @@ public class AppIDAuthorizationManagerTests: XCTestCase {
AppIDAuthorizationManagerTests.manager?.obtainAuthorization(completionHandler: callback)
tokenManager.verify()
}

public func testObtainAuthorizationSuccessAfterRefreshFails() {
MockAuthorizationManager.res = "success"
AppIDAuthorizationManagerTests.manager?.oAuthManager.authorizationManager = MockAuthorizationManager(oAuthManager: (AppIDAuthorizationManagerTests.manager?.oAuthManager)!)
Expand All @@ -149,17 +149,17 @@ public class AppIDAuthorizationManagerTests: XCTestCase {


public func testObtainAuthorizationFailure() {

MockAuthorizationManager.res = "failure"
AppIDAuthorizationManagerTests.manager?.oAuthManager.authorizationManager = MockAuthorizationManager(oAuthManager: (AppIDAuthorizationManagerTests.manager?.oAuthManager)!)
let callback:BMSCompletionHandler = {(response:Response?, error:Error?) in
XCTAssertNil(response)
XCTAssertEqual((error as? AuthorizationError)?.description, "someerr")
}
AppIDAuthorizationManagerTests.manager?.obtainAuthorization(completionHandler: callback)

}

public func testObtainAuthorizationFailsAfterRefreshFails() {
MockAuthorizationManager.res = "failure"
AppIDAuthorizationManagerTests.manager?.oAuthManager.authorizationManager = MockAuthorizationManager(oAuthManager: (AppIDAuthorizationManagerTests.manager?.oAuthManager)!)
Expand Down Expand Up @@ -187,13 +187,13 @@ public class AppIDAuthorizationManagerTests: XCTestCase {
self.iToken = idToken
super.init(appid: AppIDAuthorizationManagerTests.appid!)
}

public override var accessToken: AccessToken? {
get {
return aToken
}
}

public override var identityToken: IdentityToken? {
get {
return iToken
Expand All @@ -206,8 +206,8 @@ public class AppIDAuthorizationManagerTests: XCTestCase {
XCTAssertNil(AppIDAuthorizationManagerMock(accessToken: accessToken,idToken: nil).cachedAuthorizationHeader)
XCTAssertNil(AppIDAuthorizationManagerMock(accessToken: nil,idToken: idToken).cachedAuthorizationHeader)
XCTAssertEqual((AppIDAuthorizationManagerMock(accessToken: accessToken,idToken: idToken).cachedAuthorizationHeader), "Bearer " + accessToken!.raw + " " + idToken!.raw)



}
}
Loading

0 comments on commit 7a4978a

Please sign in to comment.