Skip to content

Commit 5e16e19

Browse files
committed
fix(test): DownloadCert now doesn't create a directory with the file name
1 parent c60d745 commit 5e16e19

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

auth_providers/auth_oauth_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -510,23 +510,23 @@ func DownloadCertificate(input string, outputPath string) error {
510510

511511
// Set default output path to current working directory if none is provided
512512
if outputPath == "" {
513-
cwd, err := os.Getwd()
514-
if err != nil {
515-
return fmt.Errorf("failed to get current working directory: %v", err)
513+
cwd, cwdErr := os.Getwd()
514+
if cwdErr != nil {
515+
return fmt.Errorf("failed to get current working directory: %v", cwdErr)
516516
}
517517
outputPath = cwd
518518
}
519519

520520
// Ensure the output directory exists
521-
if err := os.MkdirAll(outputPath, os.ModePerm); err != nil {
522-
return fmt.Errorf("failed to create output directory: %v", err)
521+
if dirErr := os.MkdirAll(filepath.Dir(outputPath), os.ModePerm); dirErr != nil {
522+
return fmt.Errorf("failed to create output directory: %v", dirErr)
523523
}
524524

525525
// Create the output file
526-
outputFile := filepath.Join(outputPath, fmt.Sprintf("%s.crt", hostname))
527-
file, err := os.Create(outputFile)
528-
if err != nil {
529-
return fmt.Errorf("failed to create file %s: %v", outputFile, err)
526+
outputFile := filepath.Join(outputPath)
527+
file, fErr := os.Create(outputFile)
528+
if fErr != nil {
529+
return fmt.Errorf("failed to create file %s: %v", outputFile, fErr)
530530
}
531531
defer file.Close()
532532

@@ -540,9 +540,9 @@ func DownloadCertificate(input string, outputPath string) error {
540540
}
541541

542542
// Send an HTTP GET request to the server
543-
resp, err := httpClient.Get(input)
544-
if err != nil {
545-
return fmt.Errorf("failed to connect to %s: %v", input, err)
543+
resp, respErr := httpClient.Get(input)
544+
if respErr != nil {
545+
return fmt.Errorf("failed to connect to %s: %v", input, respErr)
546546
}
547547
defer resp.Body.Close()
548548

@@ -554,14 +554,14 @@ func DownloadCertificate(input string, outputPath string) error {
554554

555555
// Write the entire certificate chain to the output file in PEM format
556556
for _, cert := range tlsConnState.PeerCertificates {
557-
err = pem.Encode(
557+
pemErr := pem.Encode(
558558
file, &pem.Block{
559559
Type: "CERTIFICATE",
560560
Bytes: cert.Raw,
561561
},
562562
)
563-
if err != nil {
564-
return fmt.Errorf("failed to write certificate to file: %v", err)
563+
if pemErr != nil {
564+
return fmt.Errorf("failed to write certificate to file: %v", pemErr)
565565
}
566566
}
567567

0 commit comments

Comments
 (0)