github.com/Axway/agent-sdk@v1.1.101/pkg/authz/oauth/keyreader_test.go (about) 1 package oauth 2 3 import "testing" 4 5 func TestGetKey(t *testing.T) { 6 cases := []struct { 7 description string 8 kr *keyReader 9 }{ 10 { 11 "no password", 12 &keyReader{ 13 privKey: "../../apic/auth/testdata/private_key.pem", 14 }, 15 }, 16 { 17 "with empty password file", 18 &keyReader{ 19 privKey: "../../apic/auth/testdata/private_key.pem", 20 password: "../../apic/auth/testdata/password_empty", 21 }, 22 }, 23 { 24 "with password", 25 &keyReader{ 26 privKey: "../../apic/auth/testdata/private_key_with_pwd.pem", 27 password: "../../apic/auth/testdata/password", 28 }, 29 }, 30 } 31 32 for _, testCase := range cases { 33 if _, err := testCase.kr.GetPrivateKey(); err != nil { 34 t.Errorf("testcase: %s: failed to read rsa key %s", testCase.description, err) 35 } 36 } 37 } 38 39 func TestGetPublicKey(t *testing.T) { 40 cases := []struct { 41 description string 42 kr *keyReader 43 }{ 44 { 45 "with public key", 46 &keyReader{ 47 publicKey: "../../apic/auth/testdata/public_key", 48 }, 49 }, 50 { 51 "with private and public key", 52 &keyReader{ 53 privKey: "../../apic/auth/testdata/private_key.pem", 54 publicKey: "../../apic/auth/testdata/public_key", 55 }, 56 }, 57 { 58 "with private, public key, and password", 59 &keyReader{ 60 privKey: "../../apic/auth/testdata/private_key_with_pwd.pem", 61 password: "../../apic/auth/testdata/password", 62 publicKey: "../../apic/auth/testdata/public_key", 63 }, 64 }, 65 } 66 for _, testCase := range cases { 67 if _, err := testCase.kr.GetPublicKey(); err != nil { 68 t.Errorf("testcase: %s: failed to read public key %s", testCase.description, err) 69 } 70 } 71 }