-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We no longer need to cache ADC mechanism on disk and would instead directly call the google oauth library for ADC checks (avoiding calling gcloud which is what's problematic in Windows). Tested: had a cached creds on disk, verified it was deleted with this change. Also confirmed new cached creds weren't written out for ADC mechanism. Bug: b/303046311 Change-Id: I678aae4f29608938b583d8966acdba32a40c22bd GitOrigin-RevId: 005709868f355d77b5880298f3a42cc38f6d1d62
- Loading branch information
1 parent
59544f1
commit 74710a8
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "fakes", | ||
srcs = ["fakeadc.go"], | ||
importpath = "github.com/bazelbuild/reclient/internal/pkg/auth/fakes", | ||
visibility = ["//:__subpackages__"], | ||
) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package fakes | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"net/http/httptest" | ||
"strconv" | ||
"testing" | ||
"time" | ||
) | ||
|
||
// StartTokenValidationServer sets up a fake tokeninfo endpoint that responds with the given expiry for the given token. | ||
func StartTokenValidationServer(t *testing.T, exp time.Time, validToken string) string { | ||
t.Helper() | ||
fakeTokenServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
switch r.URL.Path { | ||
case "/tokeninfo": | ||
token := r.URL.Query().Get("access_token") | ||
if token != validToken { | ||
t.Errorf("Expected query param access_token=%s, got access_token=%s", validToken, token) | ||
} | ||
resp := map[string]interface{}{ | ||
"exp": strconv.FormatInt(exp.Unix(), 10), | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
json.NewEncoder(w).Encode(resp) | ||
case "/token": | ||
resp := map[string]interface{}{ | ||
"access_token": "adcToken", | ||
"expires_in": 3600, | ||
"refresh_token": "refresh", | ||
"scope": "https://www.googleapis.com/auth/pubsub", | ||
"token_type": "Bearer", | ||
} | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(http.StatusOK) | ||
json.NewEncoder(w).Encode(resp) | ||
default: | ||
t.Errorf("Unexpected request path, got '%s'", r.URL.Path) | ||
} | ||
})) | ||
t.Cleanup(fakeTokenServer.Close) | ||
return fakeTokenServer.URL | ||
} |