Skip to content

Commit de00d9a

Browse files
authored
Refactoring Unit Tests (#221)
* Cleaning up auth tests * Reducing dependency on package variables * Removed testClient package variable * Updated unit tests * using t.Fatal instead of log.Fatal inside test cases
1 parent 761eb88 commit de00d9a

File tree

11 files changed

+279
-239
lines changed

11 files changed

+279
-239
lines changed

auth/auth.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package auth
1717

1818
import (
1919
"context"
20-
"encoding/json"
2120
"errors"
2221
"fmt"
2322
"strings"
@@ -66,12 +65,7 @@ type Client struct {
6665
projectID string
6766
signer cryptoSigner
6867
version string
69-
clock clock
70-
}
71-
72-
type signer interface {
73-
Email(ctx context.Context) (string, error)
74-
Sign(ctx context.Context, b []byte) ([]byte, error)
68+
clock internal.Clock
7569
}
7670

7771
// NewClient creates a new instance of the Firebase Auth Client.
@@ -86,17 +80,10 @@ func NewClient(ctx context.Context, conf *internal.AuthConfig) (*Client, error)
8680
// Initialize a signer by following the go/firebase-admin-sign protocol.
8781
if conf.Creds != nil && len(conf.Creds.JSON) > 0 {
8882
// If the SDK was initialized with a service account, use it to sign bytes.
89-
var sa serviceAccount
90-
if err = json.Unmarshal(conf.Creds.JSON, &sa); err != nil {
83+
signer, err = signerFromCreds(conf.Creds.JSON)
84+
if err != nil && err != errNotAServiceAcct {
9185
return nil, err
9286
}
93-
if sa.PrivateKey != "" && sa.ClientEmail != "" {
94-
var err error
95-
signer, err = newServiceAccountSigner(sa)
96-
if err != nil {
97-
return nil, err
98-
}
99-
}
10087
}
10188
if signer == nil {
10289
if conf.ServiceAccountID != "" {
@@ -136,7 +123,7 @@ func NewClient(ctx context.Context, conf *internal.AuthConfig) (*Client, error)
136123
projectID: conf.ProjectID,
137124
signer: signer,
138125
version: "Go/Admin/" + conf.Version,
139-
clock: &systemClock{},
126+
clock: internal.SystemClock,
140127
}, nil
141128
}
142129

0 commit comments

Comments
 (0)