Skip to content

Commit

Permalink
Disable NSURLSession cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hzalaz committed May 25, 2018
1 parent 5b0fc6d commit d65c1b1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 35 deletions.
22 changes: 0 additions & 22 deletions .travis.yml

This file was deleted.

4 changes: 0 additions & 4 deletions Guardian.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@
5F20380E1D5E421F0005D2E2 /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
5F20380F1D5E421F0005D2E2 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
5F2038111D5E42AD0005D2E2 /* .gitignore */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
5F2038141D5E43CD0005D2E2 /* .travis.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .travis.yml; sourceTree = "<group>"; };
5F2038161D5E43DD0005D2E2 /* .env */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = .env; path = script/.env; sourceTree = "<group>"; };
5F2038181D5E46210005D2E2 /* Gemfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Gemfile; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -406,8 +404,6 @@
isa = PBXGroup;
children = (
5F2038181D5E46210005D2E2 /* Gemfile */,
5F2038161D5E43DD0005D2E2 /* .env */,
5F2038141D5E43CD0005D2E2 /* .travis.yml */,
5F2038111D5E42AD0005D2E2 /* .gitignore */,
5F20380C1D5E421F0005D2E2 /* Cartfile.resolved */,
5F20380D1D5E421F0005D2E2 /* Cartfile.private */,
Expand Down
24 changes: 16 additions & 8 deletions Guardian/Guardian.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

import Foundation

let nonCachedSession: URLSession = {
let config = URLSessionConfiguration.default
config.requestCachePolicy = .reloadIgnoringLocalCacheData
config.urlCache = nil

return URLSession.init(configuration: config)
}()

/**
Creates a low level API client for Guardian MFA server

Expand All @@ -36,7 +44,7 @@ import Foundation

- seealso: Guardian.API
*/
public func api(forDomain domain: String, session: URLSession = .shared) -> API {
public func api(forDomain domain: String, session: URLSession = nonCachedSession) -> API {
return api(url: url(from: domain)!, session: session)
}

Expand All @@ -54,7 +62,7 @@ public func api(forDomain domain: String, session: URLSession = .shared) -> API

- seealso: Guardian.API
*/
public func api(url: URL, session: URLSession = .shared) -> API {
public func api(url: URL, session: URLSession = nonCachedSession) -> API {
return APIClient(baseUrl: url, session: session)
}

Expand All @@ -76,7 +84,7 @@ public func api(url: URL, session: URLSession = .shared) -> API {

- seealso: Guardian.Authentication
*/
public func authentication(forDomain domain: String, andEnrollment enrollment: Enrollment, session: URLSession = .shared) -> Authentication {
public func authentication(forDomain domain: String, andEnrollment enrollment: Enrollment, session: URLSession = nonCachedSession) -> Authentication {
let client = api(forDomain: domain, session: session)
return RSAAuthentication(api: client, enrollment: enrollment)
}
Expand All @@ -100,7 +108,7 @@ public func authentication(forDomain domain: String, andEnrollment enrollment: E

- seealso: Guardian.Authentication
*/
public func authentication(url: URL, andEnrollment enrollment: Enrollment, session: URLSession = .shared) -> Authentication {
public func authentication(url: URL, andEnrollment enrollment: Enrollment, session: URLSession = nonCachedSession) -> Authentication {
let client = api(url: url, session: session)
return RSAAuthentication(api: client, enrollment: enrollment)
}
Expand Down Expand Up @@ -149,7 +157,7 @@ public func authentication(url: URL, andEnrollment enrollment: Enrollment, sessi

- returns: a request to create an enrollment
*/
public func enroll(forDomain domain: String, session: URLSession = .shared, usingUri uri: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
public func enroll(forDomain domain: String, session: URLSession = nonCachedSession, usingUri uri: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
let client = api(forDomain: domain, session: session)
return EnrollRequest(api: client, enrollmentUri: uri, notificationToken: notificationToken, keyPair: keyPair)
}
Expand Down Expand Up @@ -198,7 +206,7 @@ public func enroll(forDomain domain: String, session: URLSession = .shared, usin

- returns: a request to create an enrollment
*/
public func enroll(url: URL, session: URLSession = .shared, usingUri uri: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
public func enroll(url: URL, session: URLSession = nonCachedSession, usingUri uri: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
let client = api(url: url, session: session)
return EnrollRequest(api: client, enrollmentUri: uri, notificationToken: notificationToken, keyPair: keyPair)
}
Expand Down Expand Up @@ -246,7 +254,7 @@ public func enroll(url: URL, session: URLSession = .shared, usingUri uri: String

- returns: a request to create an enrollment
*/
public func enroll(forDomain domain: String, session: URLSession = .shared, usingTicket ticket: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
public func enroll(forDomain domain: String, session: URLSession = nonCachedSession, usingTicket ticket: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
let client = api(forDomain: domain, session: session)
return EnrollRequest(api: client, enrollmentTicket: ticket, notificationToken: notificationToken, keyPair: keyPair)
}
Expand Down Expand Up @@ -294,7 +302,7 @@ public func enroll(forDomain domain: String, session: URLSession = .shared, usin

- returns: a request to create an enrollment
*/
public func enroll(url: URL, session: URLSession = .shared, usingTicket ticket: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
public func enroll(url: URL, session: URLSession = nonCachedSession, usingTicket ticket: String, notificationToken: String, keyPair: RSAKeyPair) -> EnrollRequest {
let client = api(url: url, session: session)
return EnrollRequest(api: client, enrollmentTicket: ticket, notificationToken: notificationToken, keyPair: keyPair)
}
Expand Down
2 changes: 1 addition & 1 deletion GuardianTests/APIClientSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class APIClientSpec: QuickSpec {

override func spec() {

let client = APIClient(baseUrl: ValidURL, session: URLSession.shared)
let client = APIClient(baseUrl: ValidURL, session: Guardian.nonCachedSession)

beforeEach {
stub(condition: { _ in return true }) { _ in
Expand Down

0 comments on commit d65c1b1

Please sign in to comment.