-
Notifications
You must be signed in to change notification settings - Fork 9
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
internal/testkeys: use fixed keys in unit tests #1191
Open
davidweisse
wants to merge
1
commit into
main
Choose a base branch
from
dav/fixed-test-keys
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
burgerdev
reviewed
Jan 27, 2025
internal/testkeys/testkeys.go
Outdated
Comment on lines
50
to
53
if _, ok := key.(*T); !ok { | ||
return nil, fmt.Errorf("invalid key type: %T", key) | ||
} | ||
return key.(*T), nil |
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.
Suggested change
if _, ok := key.(*T); !ok { | |
return nil, fmt.Errorf("invalid key type: %T", key) | |
} | |
return key.(*T), nil | |
typedKey, ok := key.(*T); | |
if !ok { | |
return nil, fmt.Errorf("invalid key type: %T", key) | |
} | |
return typedKey, nil |
internal/testkeys/testkeys.go
Outdated
"MIIJQwIBADANBgkqhkiG9w0BAQEFAASCCS0wggkpAgEAAoICAQCsx64xAyx2Gs+/JhojC9A/XxpdbeTNIYWNZUgVcIBNmbEVae+tHmWTIjnNUyjlIX8CtzUAneeqfU2mOWglC1tPBXfi6H5TwYTsGIUXIb4IqBJrOoqQaIIxYZpENcFMEVxJa0m1y1HJAuf6WH0VS+iG2RX1yizFOpMZkWtOZPOF0PXs111c4yv9Y28bo4ua+LvYYJ2svYKi6LhvoARZJWMBWvXKdklESKAU6Prsi4VIMsxDlxRFwgTRJYffXfmsidzgFfruIJP2jstyMkOlMt/1Nqz+OpfxN6BR8A6Dq+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BAQDQBAguuWZ52I0lMf4k6cgomn4Fn5gRGx58P/Azu/mp3LvrloLghwfImMjpMAkFyVALoGxDWqEnHuNRXC8Itsyw9gJsT1o9784m7L2rtPCqid+2fReH060SYi95YZ+/rYeQGqKXKnQt27vS4izCaKvJCUOvivSFDMwKIDPKu7myqPzZQHsvcXEkS+sffE7u2Uv02CIsaVb84iComrRFX5umxDI/fXZqELatI6+WaCVBFi5PiLtIXG89gSfZInDYKs2EVba6ADJVlIvZa3TobUAMLI2VBCh7BQX6S4Tfd2WUMuWQxbGp0lUdaykIp7ZgGdIbNHY72jvOq0pHQfNRPmLRAoIBAGOJlO1Twr3v85gkLcFiSVUqkUkxefp8aYQZtxmNPq7LzHF+7B5WbWfDbsD0/xOE3vBnF2v0Ny2FsKpcxD7ntpxuKT8eHTYB6bP81rXWyUXsZkVoWYFO+QRvRROFb3na9g9n2pZru90esUC4tDGMgwQ/sDT5GYic4+kcDOhYF68muwIQhX/9rPXktqJOR3Hjp3xCvsb5TW/f5QpI9cALYDHJQIjtfR8Nn0zODZRmFRiOGX5KQ9Hdr4PnwpsZNg0t5lh0uqHRewBrV6TpKBHnupo9Xsny9Ozemj+3cQSpljUlbfAKw1wSuJP2JJbBMg3dX13YUin1nNnGyfzonYsZ2Dc=", | ||
} | ||
|
||
func New[T crypto.PrivateKey](keyString EncodedKeyString) (*T, error) { |
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 would be easier to use if the signature was
func New[T crypto.PrivateKey](t *testing.T, keyString EncodedKeyString) *T
and the function would fail the test if the key does not decode.
e2c747f
to
8121bc6
Compare
burgerdev
approved these changes
Feb 5, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
We can speed up unit tests, and make them more deterministic by using fixed keys, instead of generating them at runtime. A number of fixed keys are stored in the
internal/testkeys
package in Base64 encoded PKCS8 format, which can be used in unit tests with thetestkeys.New
function.