2019-05-04 18:48:48 +02:00
|
|
|
//
|
|
|
|
// AccountCredentialsTest.swift
|
|
|
|
// AccountTests
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 5/4/19.
|
|
|
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import XCTest
|
2019-05-04 22:14:49 +02:00
|
|
|
import RSWeb
|
2019-05-04 18:48:48 +02:00
|
|
|
@testable import Account
|
|
|
|
|
|
|
|
class AccountCredentialsTest: XCTestCase {
|
|
|
|
|
|
|
|
private var account: Account!
|
|
|
|
|
|
|
|
override func setUp() {
|
2019-05-05 22:41:20 +02:00
|
|
|
account = TestAccountManager.shared.createAccount(type: .feedbin, transport: TestTransport())
|
2019-05-04 18:48:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
override func tearDown() {
|
|
|
|
TestAccountManager.shared.deleteAccount(account)
|
|
|
|
}
|
|
|
|
|
2019-05-04 22:14:49 +02:00
|
|
|
func testCreateRetrieveDelete() {
|
2019-05-04 18:48:48 +02:00
|
|
|
|
2019-05-04 22:14:49 +02:00
|
|
|
// Make sure any left over from failed tests are gone
|
|
|
|
do {
|
2019-09-30 01:45:13 +02:00
|
|
|
try account.removeCredentials(type: .basic)
|
2019-05-04 22:14:49 +02:00
|
|
|
} catch {
|
|
|
|
XCTFail(error.localizedDescription)
|
|
|
|
}
|
|
|
|
|
2019-09-30 01:45:13 +02:00
|
|
|
var credentials: Credentials? = Credentials(type: .basic, username: "maurice", secret: "hardpasswd")
|
2019-05-04 22:14:49 +02:00
|
|
|
|
|
|
|
// Store the credentials
|
|
|
|
do {
|
|
|
|
try account.storeCredentials(credentials!)
|
|
|
|
} catch {
|
|
|
|
XCTFail(error.localizedDescription)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve them
|
|
|
|
credentials = nil
|
|
|
|
do {
|
2019-09-30 01:45:13 +02:00
|
|
|
credentials = try account.retrieveCredentials(type: .basic)
|
2019-05-04 22:14:49 +02:00
|
|
|
} catch {
|
|
|
|
XCTFail(error.localizedDescription)
|
|
|
|
}
|
2019-05-05 10:25:21 +02:00
|
|
|
|
2019-09-30 01:45:13 +02:00
|
|
|
switch credentials!.type {
|
|
|
|
case .basic:
|
|
|
|
XCTAssertEqual("maurice", credentials?.username)
|
|
|
|
XCTAssertEqual("hardpasswd", credentials?.secret)
|
|
|
|
default:
|
|
|
|
XCTFail("Expected \(CredentialsType.basic), received \(credentials!.type)")
|
2019-05-05 10:25:21 +02:00
|
|
|
}
|
2019-05-04 22:14:49 +02:00
|
|
|
|
|
|
|
// Update them
|
2019-09-30 01:45:13 +02:00
|
|
|
credentials = Credentials(type: .basic, username: "maurice", secret: "easypasswd")
|
2019-05-04 22:14:49 +02:00
|
|
|
do {
|
|
|
|
try account.storeCredentials(credentials!)
|
|
|
|
} catch {
|
|
|
|
XCTFail(error.localizedDescription)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve them again
|
|
|
|
credentials = nil
|
|
|
|
do {
|
2019-09-30 01:45:13 +02:00
|
|
|
credentials = try account.retrieveCredentials(type: .basic)
|
2019-05-04 22:14:49 +02:00
|
|
|
} catch {
|
|
|
|
XCTFail(error.localizedDescription)
|
|
|
|
}
|
2019-05-05 10:25:21 +02:00
|
|
|
|
2019-09-30 01:45:13 +02:00
|
|
|
switch credentials!.type {
|
|
|
|
case .basic:
|
|
|
|
XCTAssertEqual("maurice", credentials?.username)
|
|
|
|
XCTAssertEqual("easypasswd", credentials?.secret)
|
|
|
|
default:
|
|
|
|
XCTFail("Expected \(CredentialsType.basic), received \(credentials!.type)")
|
2019-05-05 10:25:21 +02:00
|
|
|
}
|
|
|
|
|
2019-05-04 22:14:49 +02:00
|
|
|
// Delete them
|
|
|
|
do {
|
2019-09-30 01:45:13 +02:00
|
|
|
try account.removeCredentials(type: .basic)
|
2019-05-04 22:14:49 +02:00
|
|
|
} catch {
|
|
|
|
XCTFail(error.localizedDescription)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure they are gone
|
|
|
|
do {
|
2019-09-30 01:45:13 +02:00
|
|
|
try credentials = account.retrieveCredentials(type: .basic)
|
2019-05-04 22:14:49 +02:00
|
|
|
} catch {
|
|
|
|
XCTFail(error.localizedDescription)
|
|
|
|
}
|
|
|
|
|
|
|
|
XCTAssertNil(credentials)
|
2019-05-04 18:48:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|