forked from loafle/openapi-generator-original
[Golang] enable unit test for ecdsa keys (#6593)
* Mustache template should use invokerPackage tag to generate import * Enable unit tests for ECDSA keys * fix unit test Co-authored-by: Vikrant Balyan (vvb) <vvb@cisco.com>
This commit is contained in:
parent
4bbe3cdbc9
commit
a4d679f9e5
@ -11,6 +11,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"crypto/elliptic"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
@ -126,9 +127,6 @@ func writeRandomTestRsaPemKey(t *testing.T, filePath string, bits int, format ke
|
|||||||
fmt.Printf("Wrote private key '%s'\n", filePath)
|
fmt.Printf("Wrote private key '%s'\n", filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Commented out because OpenAPITools is configured to use golang 1.8 at build time
|
|
||||||
x509.MarshalPKCS8PrivateKey is not present.
|
|
||||||
func writeRandomTestEcdsaPemKey(t *testing.T, filePath string) {
|
func writeRandomTestEcdsaPemKey(t *testing.T, filePath string) {
|
||||||
key, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
|
key, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -156,7 +154,6 @@ func writeRandomTestEcdsaPemKey(t *testing.T, filePath string) {
|
|||||||
t.Fatalf("Error encoding ECDSA private key: %v", err)
|
t.Fatalf("Error encoding ECDSA private key: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// TestHttpSignaturePrivateKeys creates private keys of various sizes, serialization format,
|
// TestHttpSignaturePrivateKeys creates private keys of various sizes, serialization format,
|
||||||
// clear-text and password encrypted.
|
// clear-text and password encrypted.
|
||||||
@ -231,24 +228,21 @@ func TestHttpSignaturePrivateKeys(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Unfortunately, currently the build environment for OpenAPITools is using an old version
|
|
||||||
of golang that does not support ECDSA keys.
|
|
||||||
{
|
{
|
||||||
privateKeyPath := "privatekey.pem"
|
privateKeyPath := "privatekey.pem"
|
||||||
authConfig := sw.HttpSignatureAuth{
|
authConfig := sw.HttpSignatureAuth{
|
||||||
KeyId: "my-key-id",
|
KeyId: "my-key-id",
|
||||||
|
PrivateKeyPath: privateKeyPath,
|
||||||
SigningScheme: "hs2019",
|
SigningScheme: "hs2019",
|
||||||
SignedHeaders: []string{"Content-Type"},
|
SignedHeaders: []string{"Content-Type"},
|
||||||
}
|
}
|
||||||
// Generate test private key.
|
// Generate test private key.
|
||||||
writeRandomTestEcdsaPemKey(t, privateKeyPath)
|
writeRandomTestEcdsaPemKey(t, privateKeyPath)
|
||||||
err := authConfig.LoadPrivateKey(privateKeyPath)
|
_, err := authConfig.ContextWithValue(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error loading private key '%s': %v", privateKeyPath, err)
|
t.Fatalf("Error loading private key '%s': %v", privateKeyPath, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeHttpSignatureAuth(t *testing.T, authConfig *sw.HttpSignatureAuth, expectSuccess bool) string {
|
func executeHttpSignatureAuth(t *testing.T, authConfig *sw.HttpSignatureAuth, expectSuccess bool) string {
|
||||||
@ -654,8 +648,7 @@ func TestInvalidHttpSignatureConfiguration(t *testing.T) {
|
|||||||
var err error
|
var err error
|
||||||
var authConfig sw.HttpSignatureAuth
|
var authConfig sw.HttpSignatureAuth
|
||||||
|
|
||||||
authConfig = sw.HttpSignatureAuth{
|
authConfig = sw.HttpSignatureAuth{}
|
||||||
}
|
|
||||||
_, err = authConfig.ContextWithValue(context.Background())
|
_, err = authConfig.ContextWithValue(context.Background())
|
||||||
if err == nil || !strings.Contains(err.Error(), "Key ID must be specified") {
|
if err == nil || !strings.Contains(err.Error(), "Key ID must be specified") {
|
||||||
t.Fatalf("Invalid configuration: %v", err)
|
t.Fatalf("Invalid configuration: %v", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user