OTP/OTPKitTests/OTPGeneratorTests.swift

26 lines
774 B
Swift
Raw Permalink Normal View History

2021-08-24 22:19:31 +00:00
//
// OTPGeneratorTests.swift
// OTPKitTests
//
// Created by Shadowfacts on 8/21/21.
//
import XCTest
@testable import OTPKit
class OTPGeneratorTests: XCTestCase {
func testGenerateTOTP() {
let key = TOTPKey(urlComponents: URLComponents(string: "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example")!)!
let result = OTPGenerator.generate(key: key, counter: 54319307)
XCTAssertEqual(result, "155456")
}
func testPadWithZeroes() {
let key = TOTPKey(urlComponents: URLComponents(string: "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example")!)!
let result = OTPGenerator.generate(key: key, counter: 54319378)
XCTAssertEqual(result, "095891")
}
}