-
Notifications
You must be signed in to change notification settings - Fork 1
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 #4 from EladLeev/ca-certs-support
Add CA cert support, bump go version
- Loading branch information
Showing
5 changed files
with
89 additions
and
17 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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/x509" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestLoadKey(t *testing.T) { | ||
caCertFile, err := os.CreateTemp("", "cacert*.pem") | ||
if err != nil { | ||
t.Fatalf("failed to create temporary file: %s", err) | ||
} | ||
defer os.Remove(caCertFile.Name()) | ||
|
||
caCertData := []byte(` | ||
-----BEGIN CERTIFICATE----- | ||
MIIBwjCCAWugAwIBAgIUTvn+Zc80K0mGpMAoGCCqGSM49BAMCMFMxKTAnBgNV | ||
BAMMIDFwcGxlIENlcnRpZmljYXRlIEF1dGhvcml0eTAeFw0yMjAyMTcxMDU3 | ||
MTlaFw0yMjAzMTcxMDU3MTlaMFMxKTAnBgNVBAMMIDFwcGxlIENlcnRpZmlj | ||
YXRlIEF1dGhvcml0eTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABLh6FJzh | ||
Kj/ISL9Rbhg0N14O/r5WWqNw4euBJNzPbNybc+n4ebNkMttcV6U9az6POoyG | ||
Ucky6hGz2jBBRGaUuV6jUDBOMB0GA1UdDgQWBBQ2Wpqw4q3iG4nJZc+uM7N/ | ||
Y4qr4DAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG | ||
AQUFBwMCMCAGA1UdEQQZMBeCFGFwaWtleS5jb22CCnN1Ym1pdC5jb20wCgYI | ||
KoZIzj0EAwIDSAAwRQIgZH1OqzW8NfBvZHXrNmlT0TtIJ0QQs+z7E2N1blSC | ||
X/0CIQDKuZwuAQzS1aA90xSgbbVi/TuV7Yj4l4uV7lRGkW8HvA== | ||
-----END CERTIFICATE----- | ||
`) | ||
if _, err := caCertFile.Write(caCertData); err != nil { | ||
t.Fatalf("failed to write to temporary file: %s", err) | ||
} | ||
|
||
tlsConfig := loadKey(caCertFile.Name()) | ||
|
||
if tlsConfig.RootCAs == nil { | ||
t.Error("RootCAs is nil") | ||
} | ||
|
||
if !tlsConfig.RootCAs.Equal(x509.NewCertPool()) { | ||
t.Error("something is wrong with the RootCAs") | ||
} | ||
|
||
} |
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