Skip to content

Commit

Permalink
Remove unused invalid token fallbacks in token deserialization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrubin committed Dec 29, 2022
1 parent fbd02eb commit 13231d4
Showing 1 changed file with 19 additions and 55 deletions.
74 changes: 19 additions & 55 deletions Tests/TokenSerializationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// TokenSerializationTests.swift
// OneTimePassword
//
// Copyright (c) 2014-2018 Matt Rubin and the OneTimePassword authors
// Copyright (c) 2014-2022 Matt Rubin and the OneTimePassword authors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -61,8 +61,7 @@ class TokenSerializationTests: XCTestCase {

// MARK: mark - Brute Force Tests

// swiftlint:disable:next function_body_length
func testDeserialization() {
func testDeserialization() throws {
for factor in factors {
for name in names {
for issuer in issuers {
Expand Down Expand Up @@ -98,31 +97,14 @@ class TokenSerializationTests: XCTestCase {
let url = urlComponents.url!

// Create the token
let token = try? Token(url: url)

// Note: `try? Token(url:)` will return nil if the token described by the URL is
// invalid.
if let token {
XCTAssertEqual(token.generator.factor, factor, "Incorrect token type")
XCTAssertEqual(token.name, name, "Incorrect token name")
XCTAssertEqual(token.issuer, issuer, "Incorrect token issuer")
XCTAssertEqual(token.generator.secret, secret, "Incorrect token secret")
XCTAssertEqual(token.generator.algorithm, algorithm, "Incorrect token algorithm")
XCTAssertEqual(token.generator.digits, digitNumber, "Incorrect token digits")
} else {
// If nil was returned from `try? Token(url:)`, create the same token manually and
// ensure it's invalid.
XCTAssertThrowsError(
Token(
name: name,
issuer: issuer,
generator: try Generator(
factor: factor,
secret: secret,
algorithm: algorithm,
digits: digitNumber)),
"The token should be invalid")
}
let token = try Token(url: url)

XCTAssertEqual(token.generator.factor, factor, "Incorrect token type")
XCTAssertEqual(token.name, name, "Incorrect token name")
XCTAssertEqual(token.issuer, issuer, "Incorrect token issuer")
XCTAssertEqual(token.generator.secret, secret, "Incorrect token secret")
XCTAssertEqual(token.generator.algorithm, algorithm, "Incorrect token algorithm")
XCTAssertEqual(token.generator.digits, digitNumber, "Incorrect token digits")
}
}
}
Expand Down Expand Up @@ -151,8 +133,7 @@ class TokenSerializationTests: XCTestCase {
}
}

// swiftlint:disable:next function_body_length
func testTokenWithURLAndSecret() {
func testTokenWithURLAndSecret() throws {
for factor in factors {
for name in names {
for issuer in issuers {
Expand Down Expand Up @@ -187,31 +168,14 @@ class TokenSerializationTests: XCTestCase {
let url = urlComponents.url!

// Create the token
let token = try? Token(url: url, secret: secret)

// Note: `try? Token(url:secret:)` will return nil if the token described by the URL is
// invalid.
if let token {
XCTAssertEqual(token.generator.factor, factor, "Incorrect token type")
XCTAssertEqual(token.name, name, "Incorrect token name")
XCTAssertEqual(token.issuer, issuer, "Incorrect token issuer")
XCTAssertEqual(token.generator.secret, secret, "Incorrect token secret")
XCTAssertEqual(token.generator.algorithm, algorithm, "Incorrect token algorithm")
XCTAssertEqual(token.generator.digits, digitNumber, "Incorrect token digits")
} else {
// If nil was returned from `try? Token(url:secret:)` create the same token manually
// and ensure it's invalid.
XCTAssertThrowsError(
Token(
name: name,
issuer: issuer,
generator: try Generator(
factor: factor,
secret: secret,
algorithm: algorithm,
digits: digitNumber)),
"The token should be invalid")
}
let token = try Token(url: url, secret: secret)

XCTAssertEqual(token.generator.factor, factor, "Incorrect token type")
XCTAssertEqual(token.name, name, "Incorrect token name")
XCTAssertEqual(token.issuer, issuer, "Incorrect token issuer")
XCTAssertEqual(token.generator.secret, secret, "Incorrect token secret")
XCTAssertEqual(token.generator.algorithm, algorithm, "Incorrect token algorithm")
XCTAssertEqual(token.generator.digits, digitNumber, "Incorrect token digits")
}
}
}
Expand Down

0 comments on commit 13231d4

Please sign in to comment.