OTP/OTPKitTests/OTPGeneratorTests.swift

26 lines
774 B
Swift

//
// 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")
}
}