-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: add tests for reading TLS private keys
This commit adds some test cases to verify that private keys are read, decrypted and parsed correctly. Signed-off-by: Andreas Auernhammer <[email protected]>
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-----BEGIN EC PRIVATE KEY----- | ||
Proc-Type: 4,ENCRYPTED | ||
DEK-Info: AES-256-CBC,E1CF19C5B05C92E1D8D88867779455F8 | ||
|
||
hX5Pwa91m/+DGSsE4ON34/fsFyXOakpjnYK7IrbVWHagbMcDgDGTgwkeCqlEX7U/ | ||
BQiX8oGFR/ff+R+TcLRI6tGfmns9B4QS3RVMeY965F1zHysMn/jjIgzQyfmo8YNI | ||
K/11h1SW8SEmbMzmCIhnagYmt/JQrjJVbgGlQgxHV0w= | ||
-----END EC PRIVATE KEY----- |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-----BEGIN EC PRIVATE KEY----- | ||
MHcCAQEEIB4u/+f//HoqSAdVd9DN91JRhQoHLml+/gbvK91SYbK5oAoGCCqGSM49 | ||
AwEHoUQDQgAEZwWOkBVrkeLKYE5QFwDzDDHwkBjiVFJ+BgXOaXHTkRcjclh7k85r | ||
wx4zTr/x27oWtlDusD/JTa8dSqJADEF3HA== | ||
-----END EC PRIVATE KEY----- |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2021 - MinIO, Inc. All rights reserved. | ||
// Use of this source code is governed by the AGPLv3 | ||
// license that can be found in the LICENSE file. | ||
|
||
package http | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var readPrivateKeyTests = []struct { | ||
FilePath string | ||
Password string | ||
ShouldFail bool | ||
}{ | ||
{FilePath: "testdata/privatekeys/plaintext.pem", Password: ""}, // 0 | ||
{FilePath: "testdata/privatekeys/plaintext.pem", Password: "ignored_password"}, // 1 | ||
{FilePath: "testdata/privatekeys/encrypted.pem", Password: "correct_password"}, // 2 | ||
{FilePath: "testdata/privatekeys/encrypted.pem", Password: "", ShouldFail: true}, // 3 | ||
{FilePath: "testdata/privatekeys/encrypted.pem", Password: "incorrect_password", ShouldFail: true}, // 4 | ||
} | ||
|
||
func TestReadPrivateKey(t *testing.T) { | ||
for i, test := range readPrivateKeyTests { | ||
_, err := readPrivateKey(test.FilePath, test.Password) | ||
if err != nil && !test.ShouldFail { | ||
t.Fatalf("Test %d: failed to read private key %q: %v", i, test.FilePath, err) | ||
} | ||
if err == nil && test.ShouldFail { | ||
t.Fatalf("Test %d: reading private key %q should have failed", i, test.FilePath) | ||
} | ||
} | ||
} |