@@ -10,7 +10,6 @@ import (
1010 "context"
1111 "crypto"
1212 "crypto/x509"
13- "encoding/base64"
1413 "encoding/json"
1514 "fmt"
1615 "io"
@@ -23,7 +22,6 @@ import (
2322 "github.com/AzureAD/microsoft-authentication-library-for-go/apps/confidential"
2423 "github.com/AzureAD/microsoft-authentication-library-for-go/apps/errors"
2524 "github.com/AzureAD/microsoft-authentication-library-for-go/apps/public"
26- "golang.org/x/crypto/pkcs12"
2725)
2826
2927const (
@@ -39,6 +37,7 @@ const (
3937 // Default values
4038 defaultClientId = "f62c5ae3-bf3a-4af5-afa8-a68b800396e9"
4139 pemFile = "../../../cert.pem"
40+ ccaPemFile = "../../../ccaCert.pem"
4241)
4342
4443var httpClient = http.Client {}
@@ -98,7 +97,7 @@ type secret struct {
9897}
9998
10099func newLabClient () (* labClient , error ) {
101- cert , privateKey , err := getCertDataFromFile ()
100+ cert , privateKey , err := getCertDataFromFile (pemFile )
102101 if err != nil {
103102 return nil , fmt .Errorf ("Could not get cert data: %w" , err )
104103 }
@@ -116,8 +115,8 @@ func newLabClient() (*labClient, error) {
116115 return & labClient {app : app }, nil
117116}
118117
119- func getCertDataFromFile () ([]* x509.Certificate , crypto.PrivateKey , error ) {
120- data , err := os .ReadFile (pemFile )
118+ func getCertDataFromFile (filePath string ) ([]* x509.Certificate , crypto.PrivateKey , error ) {
119+ data , err := os .ReadFile (filePath )
121120 if err != nil {
122121 fmt .Printf ("Error finding certificate: %v\n " , err )
123122 }
@@ -487,25 +486,13 @@ func TestAdfsToken(t *testing.T) {
487486 if testing .Short () {
488487 t .Skip ("skipping integration test" )
489488 }
490- labClient , err := newLabClient ()
491- if err != nil {
492- t .Fatalf ("TestAccountFromCache: on newLabClient(): got err == %s, want err == nil" , errors .Verbose (err ))
493- }
494- ctx := context .Background ()
495- secret , err := labClient .secret (ctx , url.Values {"Secret" : []string {"IDLABS-APP-Confidential-Client-Cert-OnPrem" }})
496- if err != nil {
497- t .Fatalf ("TestAccountFromCache: failed to fetch secret, %s" , errors .Verbose (err ))
498- }
499- pfxData , err := base64 .StdEncoding .DecodeString (secret )
500- if err != nil {
501- t .Fatalf ("Failed to decode base64 data: %v" , err )
502- }
503- privateKey , cert , err := pkcs12 .Decode (pfxData , "" )
489+
490+ cert , privateKey , err := getCertDataFromFile (ccaPemFile )
504491 if err != nil {
505- t .Fatalf ( "Failed to decode PFX data: %v " , err )
492+ t .Fatal ( "Could not get cert data: %w " , err )
506493 }
507494
508- cred , err := confidential .NewCredFromCert ([] * x509. Certificate { cert } , privateKey )
495+ cred , err := confidential .NewCredFromCert (cert , privateKey )
509496 if err != nil {
510497 panic (err )
511498 }
0 commit comments