Separate parser and helpers from Password class for better testability
This commit is contained in:
parent
2abbceb2e9
commit
7c12263458
17 changed files with 913 additions and 537 deletions
29
passKitTests/Helpers/PasswordHelpersTest.swift
Normal file
29
passKitTests/Helpers/PasswordHelpersTest.swift
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// PasswordHelpersTest.swift
|
||||
// passKitTests
|
||||
//
|
||||
// Created by Danny Moesch on 30.09.18.
|
||||
// Copyright © 2018 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
import OneTimePassword
|
||||
import XCTest
|
||||
|
||||
@testable import passKit
|
||||
|
||||
class PasswordHelpersTest: XCTestCase {
|
||||
|
||||
func testOtpType() {
|
||||
let secret = "secret".data(using: .utf8)!
|
||||
|
||||
let totpGenerator = Generator(factor: .timer(period: 30.0), secret: secret, algorithm: .sha1, digits: 6)!
|
||||
let totpToken = Token(name: "", issuer: "", generator: totpGenerator)
|
||||
XCTAssertEqual(OtpType(token: totpToken), .totp)
|
||||
|
||||
let hotpGenerator = Generator(factor: .counter(4), secret: secret, algorithm: .sha1, digits: 6)!
|
||||
let hotpToken = Token(name: "", issuer: "", generator: hotpGenerator)
|
||||
XCTAssertEqual(OtpType(token: hotpToken), .hotp)
|
||||
|
||||
XCTAssertEqual(OtpType(token: nil), .none)
|
||||
}
|
||||
}
|
||||
35
passKitTests/Helpers/StringExtensionTest.swift
Normal file
35
passKitTests/Helpers/StringExtensionTest.swift
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// StringExtensionTest.swift
|
||||
// passKitTests
|
||||
//
|
||||
// Created by Danny Moesch on 30.09.18.
|
||||
// Copyright © 2018 Bob Sun. All rights reserved.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
|
||||
@testable import passKit
|
||||
|
||||
class StringExtensionTest: XCTestCase {
|
||||
|
||||
func testStringByAddingPercentEncodingForRFC3986() {
|
||||
[
|
||||
("!#$&'()*+,/:;=?@[]^", "%21%23%24%26%27%28%29%2A%2B%2C/%3A%3B%3D?%40%5B%5D%5E"),
|
||||
("-._~/?", "-._~/?"),
|
||||
("A*b!c", "A%2Ab%21c"),
|
||||
].forEach { unencoded, encoded in
|
||||
XCTAssertEqual(unencoded.stringByAddingPercentEncodingForRFC3986(), encoded)
|
||||
}
|
||||
}
|
||||
|
||||
func testConcatenateAsLines() {
|
||||
[
|
||||
("a" | "b", "a\nb"),
|
||||
("" | "b", "\nb"),
|
||||
("a" | "", "a"),
|
||||
("" | "", ""),
|
||||
].forEach { concatenated, result in
|
||||
XCTAssertEqual(concatenated, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue