Skip to content

Commit 3263971

Browse files
committed
Fetching cert from env directly
1 parent 52417ab commit 3263971

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

apps/tests/integration/integration_test.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

2927
const (
@@ -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

4443
var httpClient = http.Client{}
@@ -98,7 +97,7 @@ type secret struct {
9897
}
9998

10099
func 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
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
github.com/kylelemons/godebug v1.1.0
99
github.com/montanaflynn/stats v0.7.0
1010
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
11-
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
1211
)
1312

1413
require golang.org/x/sys v0.5.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ github.com/montanaflynn/stats v0.7.0 h1:r3y12KyNxj/Sb/iOE46ws+3mS1+MZca1wlHQFPsY
88
github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
99
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
1010
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
11-
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
12-
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
1311
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1412
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
1513
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)