Skip to content

Commit ffad9a8

Browse files
committed
test: add test with expected behaviour
1 parent 2068cc9 commit ffad9a8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/otp/otp_element.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,4 +423,34 @@ mod test {
423423
result.unwrap_err().to_string()
424424
);
425425
}
426+
427+
#[test]
428+
fn gh_issue_548_invalid_otp_uri_label_url_encoded() {
429+
// Arrange
430+
let otp_uri = "otpauth://totp/foo%3abar?issuer=foo&secret=JBSWY3DPEHPK3PXP";
431+
432+
// Act
433+
let result = OTPElement::from_otp_uri(otp_uri);
434+
435+
// Assert
436+
assert!(result.is_ok());
437+
let actual = result.unwrap();
438+
assert_eq!("foo", actual.issuer.as_str());
439+
assert_eq!("bar", actual.label.as_str());
440+
}
441+
442+
#[test]
443+
fn gh_issue_548_invalid_otp_uri_label_non_url_encoded() {
444+
// Arrange
445+
let otp_uri = "otpauth://totp/foo:bar?issuer=foo&secret=JBSWY3DPEHPK3PXP";
446+
447+
// Act
448+
let result = OTPElement::from_otp_uri(otp_uri);
449+
450+
// Assert
451+
assert!(result.is_ok());
452+
let actual = result.unwrap();
453+
assert_eq!("foo", actual.issuer.as_str());
454+
assert_eq!("bar", actual.label.as_str());
455+
}
426456
}

0 commit comments

Comments
 (0)