Skip to content

Commit

Permalink
Merge branch 'jens/fix-crash-in-oath-url-parser'
Browse files Browse the repository at this point in the history
  • Loading branch information
jensutbult committed Dec 3, 2024
2 parents 5516907 + ef7f26e commit 786a732
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ - (instancetype)initWithURL:(NSURL *)url skipValidation:(YKFOATHCredentialTempla
*error = [YKFOATHCredentialTemplateError ykfErrorWithCode:YKFOATHCredentialTemplateErrorCodeLabel];
return nil;
}

if (urlComponents.path.length < 1) {
*error = [YKFOATHCredentialTemplateError ykfErrorWithCode:YKFOATHCredentialTemplateErrorCodeLabel];
return nil;
}

NSString *name = [urlComponents.path substringFromIndex:1];
NSString *issuer = [urlComponents queryParameterValueForName:YKFOATHCredentialURLParameterIssuer];
if ([name containsString:@":"]) {
Expand Down
8 changes: 8 additions & 0 deletions YubiKit/YubiKitTests/Tests/YKFOATHCredentialTemplateTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ - (void)test_WhenValidatorIsRequestedToValidateWithoutSecret_SecretIsNotValidate
XCTAssertNil(error);
}

- (void)test_WhenNoPathIsSet_ErrorIsReturned {
NSError *error = nil;
NSString *url = @"otpauth://totp?secret=HXDMVJECJJWSRB3HWIZR4IFUGFTMXBOZ&issuer=ACME&algorithm=SHA1&digits=6&period=30";
YKFOATHCredentialTemplate *credential = [[YKFOATHCredentialTemplate alloc] initWithURL:[NSURL URLWithString:url] skipValidation:YKFOATHCredentialTemplateValidationLabel error:&error];
XCTAssertNotNil(error);
XCTAssertNil(credential);
}

#pragma mark - Large Key Tests

- (void)test_WhenValidatorReceivesInvalidCredentialKey_ErrorIsReturnedBack {
Expand Down

0 comments on commit 786a732

Please sign in to comment.