-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathSSOAuthenticatorTests.swift
51 lines (38 loc) · 2.11 KB
/
SSOAuthenticatorTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// SSOAuthenticatorTests.swift
// SparkSDK
//
// Created by Rob Peek on 07/08/2017.
// Copyright © 2017 Cisco. All rights reserved.
//
import XCTest
@testable import SparkSDK
class SSOAuthenticatorTests: XCTestCase {
var queryItems: [URLQueryItem] = []
let email = "someuser@spark.id"
override func setUp() {
super.setUp()
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testAuthorizationUrlContainsEmail() {
let testObject = createTestObject()
let authorizationUrl = testObject.authorizationUrl()
let encodeEmail = email.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)?.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
XCTAssert((authorizationUrl?.absoluteString.contains(encodeEmail!))!, "Overriden authorization url should contain email parameter")
}
func testAuthorizationUrlAcceptsAdditionalQueryItems() {
let queryItem = URLQueryItem(name: "token", value:"sample_access_token")
queryItems = [queryItem]
let testObject = createTestObject()
if let authorizationUrl = testObject.authorizationUrl() {
XCTAssert(authorizationUrl.absoluteString.contains(queryItem.name), "Overriden authorization url should contain additional query item name")
XCTAssert(authorizationUrl.absoluteString.contains(queryItem.value!), "Overriden authorization url should contain additional query item value")
}
}
private func createTestObject(clientId: String = "clientId1", clientSecret: String = "clientSecret1", scope: String = "scope1", redirectUri: String = "https://example.com/oauth", identityProviderUri: String = "https://simple.identityprovider.example") -> SSOAuthenticator {
return SSOAuthenticator(clientId: clientId, clientSecret: clientSecret, scope: scope, redirectUri: redirectUri, email: email, identityProviderUri: identityProviderUri, queryItems: queryItems)
}
}