Revanth14 commented on code in PR #2098:
URL: https://github.com/apache/iceberg-go/pull/2098#discussion_r4211015658
##########
catalog/rest/rest_internal_test.go:
##########
@@ -102,6 +102,207 @@ func TestSignerDoesNotSignCrossOriginRedirect(t
*testing.T) {
require.Empty(t, gotToken, "the redirect target must not receive the
session token")
}
+// TestCredentialsNotSentOnCrossOriginRedirect pins that the OAuth bearer token
+// and user-supplied default headers stay on the origin that started the
request,
+// while a same-origin redirect keeps them.
+func TestCredentialsNotSentOnCrossOriginRedirect(t *testing.T) {
+ type seen struct {
+ hit bool
+ auth, apiKey, custom, agent string
+ }
+ record := func(s *seen, r *http.Request) {
+ s.hit = true
+ s.auth = r.Header.Get("Authorization")
+ s.apiKey = r.Header.Get("X-Api-Key")
+ s.custom = r.Header.Get("X-Custom")
+ s.agent = r.Header.Get("User-Agent")
+ }
+
+ var first, other, sameLanding seen
+ second := httptest.NewServer(http.HandlerFunc(func(w
http.ResponseWriter, r *http.Request) {
+ record(&other, r)
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer second.Close()
+
+ mux := http.NewServeMux()
+ mux.HandleFunc("/v1/config", func(w http.ResponseWriter, r
*http.Request) {
+ json.NewEncoder(w).Encode(map[string]any{"defaults":
map[string]any{}, "overrides": map[string]any{}})
+ })
+ mux.HandleFunc("/cross", func(w http.ResponseWriter, r *http.Request) {
+ record(&first, r)
+ http.Redirect(w, r, second.URL+"/landing",
http.StatusTemporaryRedirect)
+ })
+ mux.HandleFunc("/same", func(w http.ResponseWriter, r *http.Request) {
+ http.Redirect(w, r, "/landing", http.StatusTemporaryRedirect)
+ })
+ mux.HandleFunc("/landing", func(w http.ResponseWriter, r *http.Request)
{
+ record(&sameLanding, r)
+ w.WriteHeader(http.StatusOK)
+ })
+ srv := httptest.NewServer(mux)
+ defer srv.Close()
+
+ cat, err := NewCatalog(context.Background(), "rest", srv.URL,
+ WithOAuthToken("SECRET-CATALOG-TOKEN"),
+ WithHeaders(map[string]string{"X-Custom": "SECRET-CUSTOM"}),
+ WithAdditionalProps(iceberg.Properties{"header.X-Api-Key":
"SECRET-API-KEY"}))
+ require.NoError(t, err)
+
+ get := func(path string) {
Review Comment:
Good catch, fixed. In the reworked `TestCrossOriginRedirectNotFollowed`,
`get` takes the subtest's `t` and calls `t.Helper()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]