-
Notifications
You must be signed in to change notification settings - Fork 262
feat(auth): Recognize FIREBASE_AUTH_EMULATOR_HOST
environment variable
#414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d98ad1
feat(auth): Recognize `FIREBASE_AUTH_EMULATOR_HOST` environment variable
maku693 1f52542
Fix incorrect test error message
maku693 d792ace
Fix lint error
maku693 68a6dce
Avoid using environment variable for expected values of tests
maku693 11d9970
Define constant for the environment variable
maku693 c599191
Make token verifier panics in emulator mode
maku693 14cc3a0
Use emulated signer when FIREBASE_AUTH_EMULATOR_HOST is set
maku693 16de7ec
Fix incorrect test error message
maku693 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,12 @@ import ( | |
) | ||
|
||
const ( | ||
credEnvVar = "GOOGLE_APPLICATION_CREDENTIALS" | ||
testProjectID = "mock-project-id" | ||
testVersion = "test-version" | ||
credEnvVar = "GOOGLE_APPLICATION_CREDENTIALS" | ||
emulatorHostEnvVar = "FIREBASE_AUTH_EMULATOR_HOST" | ||
testProjectID = "mock-project-id" | ||
testVersion = "test-version" | ||
defaultIDToolkitV1Endpoint = "https://identitytoolkit.googleapis.com/v1" | ||
defaultIDToolkitV2Beta1Endpoint = "https://identitytoolkit.googleapis.com/v2beta1" | ||
) | ||
|
||
var ( | ||
|
@@ -280,6 +283,35 @@ func TestNewClientExplicitNoAuth(t *testing.T) { | |
} | ||
} | ||
|
||
func TestNewClientEmulatorHostEnvVar(t *testing.T) { | ||
emulatorHost := "localhost:9099" | ||
idToolkitV1Endpoint := "http://localhost:9099/identitytoolkit.googleapis.com/v1" | ||
idToolkitV2Beta1Endpoint := "http://localhost:9099/identitytoolkit.googleapis.com/v2beta1" | ||
|
||
os.Setenv(emulatorHostEnvVar, emulatorHost) | ||
defer os.Unsetenv(emulatorHostEnvVar) | ||
|
||
conf := &internal.AuthConfig{ | ||
Opts: []option.ClientOption{ | ||
option.WithoutAuthentication(), | ||
}, | ||
} | ||
client, err := NewClient(context.Background(), conf) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure using no-auth config is appropriate for this test. |
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
baseClient := client.baseClient | ||
if baseClient.userManagementEndpoint != idToolkitV1Endpoint { | ||
t.Errorf("baseClient.userManagementEndpoint = %q; want = %q", baseClient.userManagementEndpoint, idToolkitV1Endpoint) | ||
} | ||
if baseClient.providerConfigEndpoint != idToolkitV2Beta1Endpoint { | ||
t.Errorf("baseClient.providerConfigEndpoint = %q; want = %q", baseClient.providerConfigEndpoint, idToolkitV2Beta1Endpoint) | ||
} | ||
if baseClient.tenantMgtEndpoint != idToolkitV2Beta1Endpoint { | ||
t.Errorf("baseClient.tenantMgtEndpoint = %q; want = %q", baseClient.tenantMgtEndpoint, idToolkitV2Beta1Endpoint) | ||
} | ||
} | ||
|
||
func TestCustomToken(t *testing.T) { | ||
client := &Client{ | ||
baseClient: &baseClient{ | ||
|
@@ -1163,23 +1195,26 @@ func checkCookieVerifier(tv *tokenVerifier, projectID string) error { | |
} | ||
|
||
func checkBaseClient(client *Client, wantProjectID string) error { | ||
umc := client.baseClient | ||
if umc.userManagementEndpoint != idToolkitV1Endpoint { | ||
return fmt.Errorf("userManagementEndpoint = %q; want = %q", umc.userManagementEndpoint, idToolkitV1Endpoint) | ||
baseClient := client.baseClient | ||
if baseClient.userManagementEndpoint != defaultIDToolkitV1Endpoint { | ||
return fmt.Errorf("userManagementEndpoint = %q; want = %q", baseClient.userManagementEndpoint, defaultIDToolkitV1Endpoint) | ||
} | ||
if baseClient.providerConfigEndpoint != defaultIDToolkitV2Beta1Endpoint { | ||
return fmt.Errorf("providerConfigEndpoint = %q; want = %q", baseClient.providerConfigEndpoint, defaultIDToolkitV2Beta1Endpoint) | ||
} | ||
if umc.providerConfigEndpoint != providerConfigEndpoint { | ||
return fmt.Errorf("providerConfigEndpoint = %q; want = %q", umc.providerConfigEndpoint, providerConfigEndpoint) | ||
if baseClient.tenantMgtEndpoint != defaultIDToolkitV2Beta1Endpoint { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the check for |
||
return fmt.Errorf("providerConfigEndpoint = %q; want = %q", baseClient.providerConfigEndpoint, defaultIDToolkitV2Beta1Endpoint) | ||
} | ||
if umc.projectID != wantProjectID { | ||
return fmt.Errorf("projectID = %q; want = %q", umc.projectID, wantProjectID) | ||
if baseClient.projectID != wantProjectID { | ||
return fmt.Errorf("projectID = %q; want = %q", baseClient.projectID, wantProjectID) | ||
} | ||
|
||
req, err := http.NewRequest(http.MethodGet, "https://firebase.google.com", nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, opt := range umc.httpClient.Opts { | ||
for _, opt := range baseClient.httpClient.Opts { | ||
opt(req) | ||
} | ||
version := req.Header.Get("X-Client-Version") | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.