-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #445 from libgit2/safer-signature
Safe signature
- Loading branch information
Showing
2 changed files
with
71 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -542,6 +542,56 @@ | |
}); | ||
}); | ||
|
||
describe(@"-userSignatureForNow", ^{ | ||
static NSString * const userName = @"johnsmith"; | ||
static NSString * const email = @"[email protected]"; | ||
|
||
__block GTConfiguration *configuration; | ||
|
||
beforeEach(^{ | ||
configuration = [repository configurationWithError:NULL]; | ||
expect(configuration).notTo(beNil()); | ||
}); | ||
|
||
it(@"should use the values from the config", ^{ | ||
[configuration setString:userName forKey:@"user.name"]; | ||
[configuration setString:email forKey:@"user.email"]; | ||
|
||
GTSignature *signature = [repository userSignatureForNow]; | ||
expect(signature.name).to(equal(userName)); | ||
expect(signature.email).to(equal(email)); | ||
}); | ||
|
||
describe(@"invalid values", ^{ | ||
it(@"should use a default value if the name is empty", ^{ | ||
[configuration setString:@"" forKey:@"user.name"]; | ||
[configuration setString:email forKey:@"user.email"]; | ||
|
||
GTSignature *signature = [repository userSignatureForNow]; | ||
expect(@(signature.name.length)).to(beGreaterThan(@0)); | ||
expect(@(signature.email.length)).to(beGreaterThan(@0)); | ||
}); | ||
|
||
it(@"should use a default value if the email is empty", ^{ | ||
[configuration setString:userName forKey:@"user.name"]; | ||
[configuration setString:@"" forKey:@"user.email"]; | ||
|
||
GTSignature *signature = [repository userSignatureForNow]; | ||
expect(@(signature.name.length)).to(beGreaterThan(@0)); | ||
expect(@(signature.email.length)).to(beGreaterThan(@0)); | ||
}); | ||
|
||
it(@"should use a default value if the email contains angled brackets", ^{ | ||
[configuration setString:userName forKey:@"user.name"]; | ||
[configuration setString:@"<[email protected]>" forKey:@"user.email"]; | ||
|
||
GTSignature *signature = [repository userSignatureForNow]; | ||
expect(@(signature.name.length)).to(beGreaterThan(@0)); | ||
expect(@(signature.email.length)).to(beGreaterThan(@0)); | ||
}); | ||
}); | ||
}); | ||
|
||
afterEach(^{ | ||
[self tearDown]; | ||
}); | ||
|