Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Credentials Manager Test #325

Merged
merged 6 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build-iOS-Swift-5.1:
macos:
xcode: "11.0.0"
xcode: "11.2.0"
shell: /bin/bash --login -eo pipefail
environment:
LC_ALL: en_US.UTF-8
Expand All @@ -11,14 +11,10 @@ jobs:
HOMEBREW_TEMP: ~/homebrew-temp
HOMEBREW_NO_AUTO_UPDATE: 1
steps:
- run:
name: Set Ruby Version
command: echo "ruby-2.5" > ~/.ruby-version
- checkout
- run: |
brew install swiftlint
bundle install --without=development
grep -lR "shouldUseLaunchSchemeArgsEnv" *.* --null | xargs -0 sed -i '' -e 's/shouldUseLaunchSchemeArgsEnv = "YES"/shouldUseLaunchSchemeArgsEnv = "YES" codeCoverageEnabled = "YES"/g'
- run:
name: Bootstrap
command: bundle exec fastlane ios bootstrap
Expand All @@ -29,6 +25,14 @@ jobs:
SCHEME: Auth0.iOS
DEVICE: iPhone 8
FASTLANE_EXPLICIT_OPEN_SIMULATOR: 2
- run: |
cd Build/Build/ProfileData
cd $(ls -d */|head -n 1)
directory=${PWD##*/}
pathCoverage=Build/Build/ProfileData/${directory}/Coverage.profdata
cd ../../../../
xcrun llvm-cov export -format="lcov" -instr-profile $pathCoverage Build/Build/Products/Debug-iphonesimulator/standard-swift.app/standard-swift > info.lcov
bash <(curl -s https://codecov.io/bash)
- save_cache:
key: dependency-cache
paths:
Expand Down Expand Up @@ -60,8 +64,6 @@ jobs:
SCHEME: Auth0.iOS
DEVICE: iPhone 8
FASTLANE_EXPLICIT_OPEN_SIMULATOR: 2
- run: |
bash <(curl -s https://codecov.io/bash) -J 'Auth0'
- save_cache:
key: dependency-cache
paths:
Expand Down
2 changes: 2 additions & 0 deletions Auth0.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,7 @@
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_GENERATE_TEST_COVERAGE_FILES = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand Down Expand Up @@ -2181,6 +2182,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_GENERATE_TEST_COVERAGE_FILES = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
Expand Down
9 changes: 3 additions & 6 deletions Auth0/CredentialsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,17 @@ public struct CredentialsManager {

func hasExpired(_ credentials: Credentials) -> Bool {

var hasATExpired = true
var hasIDTExpired = true

if let expiresIn = credentials.expiresIn {
if expiresIn > Date() { hasATExpired = false }
if expiresIn < Date() { return true }
}

if let token = credentials.idToken,
let tokenDecoded = decode(jwt: token),
let exp = tokenDecoded["exp"] as? Double {
if Date(timeIntervalSince1970: exp) > Date() { hasIDTExpired = false }
if Date(timeIntervalSince1970: exp) < Date() { return true }
}

return hasATExpired || hasIDTExpired
return false
}
}

Expand Down
2 changes: 1 addition & 1 deletion Auth0Tests/CredentialsManagerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class CredentialsManagerSpec: QuickSpec {
expect(credentialsManager.hasValid()).to(beTrue())
}

fit("should not be valid when at valid and id token expired") {
it("should not be valid when at valid and id token expired") {
let credentials = Credentials(accessToken: AccessToken, tokenType: TokenType, idToken: ExpiredToken, refreshToken: nil, expiresIn: Date(timeIntervalSinceNow: ExpiresIn))
expect(credentialsManager.store(credentials: credentials)).to(beTrue())
expect(credentialsManager.hasValid()).to(beFalse())
Expand Down