-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CBG-1966 enable staticcheck #6556
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -35,27 +35,30 @@ func BenchmarkBcryptCostTimes(b *testing.B) { | |
|
||
for i := minCostToTest; i < maxCostToTest; i++ { | ||
b.Run(fmt.Sprintf("cost%d", i), func(bn *testing.B) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Benchmark looks wrong as-is anyway (no b.N loop) Maybe we should just swap this to a test that logs the values, as we get the same one-off benefit even without assertions. // TestBcryptCostTimes will output the time it takes to hash a password with each bcrypt cost value
func TestBcryptCostTimes(t *testing.T) {
// Little value in running this regularly. Might be useful for one-off informational purposes
t.Skip("Test disabled")
minCostToTest := bcrypt.DefaultCost
maxCostToTest := bcrypt.DefaultCost + 5
for i := minCostToTest; i < maxCostToTest; i++ {
t.Run(fmt.Sprintf("cost%d", i), func(t *testing.T) {
startTime := time.Now()
_, err := bcrypt.GenerateFromPassword([]byte("hunter2"), i)
duration := time.Since(startTime)
t.Logf("bcrypt.GenerateFromPassword with cost %d took: %v", i, duration)
assert.NoError(t, err)
})
}
}
|
||
bn.N = 1 | ||
_, err := bcrypt.GenerateFromPassword([]byte("hunter2"), i) | ||
assert.NoError(bn, err) | ||
}) | ||
} | ||
} | ||
|
||
// TestBcryptDefaultCostTime will ensure that the default bcrypt cost takes at least a 'reasonable' amount of time | ||
// If this test fails, it suggests maybe we need to think about increasing the default cost... | ||
func TestBcryptDefaultCostTime(t *testing.T) { | ||
// Modest 2.2GHz macbook i7 takes ~80ms at cost 10 | ||
// Assume server CPUs are ~2x faster | ||
minimumDuration := 40 * time.Millisecond | ||
// TestBcryptCostTimes will output the time it takes to hash a password with each bcrypt cost value | ||
func TestBcryptCostTimes(t *testing.T) { | ||
// Little value in running this regularly. Might be useful for one-off informational purposes | ||
t.Skip("Test disabled") | ||
|
||
startTime := time.Now() | ||
_, err := bcrypt.GenerateFromPassword([]byte("hunter2"), DefaultBcryptCost) | ||
duration := time.Since(startTime) | ||
minCostToTest := bcrypt.DefaultCost | ||
maxCostToTest := bcrypt.DefaultCost + 5 | ||
|
||
t.Logf("bcrypt.GenerateFromPassword with cost %d took: %v", DefaultBcryptCost, duration) | ||
assert.NoError(t, err) | ||
assert.True(t, minimumDuration < duration) | ||
for i := minCostToTest; i < maxCostToTest; i++ { | ||
t.Run(fmt.Sprintf("cost%d", i), func(t *testing.T) { | ||
startTime := time.Now() | ||
_, err := bcrypt.GenerateFromPassword([]byte("hunter2"), i) | ||
duration := time.Since(startTime) | ||
|
||
t.Logf("bcrypt.GenerateFromPassword with cost %d took: %v", i, duration) | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestSetBcryptCost(t *testing.T) { | ||
|
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
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
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
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
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
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
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
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't quite look right - comparing greater than
0
seems unintentional.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is right, because it is checking that this value got updated - are you suggesting I remove this check, or move
lastUpdated
time lower thanuser.SetJWTLastUpdated(time.Now())
and useAssertTimestampGreaterThan
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, this doesn't get updated.