ci: expand CI checks and make consumer sync opt-in
- Add Go, npm, Python, and Java validation to CI - Run Go tests against PostgreSQL - Record performance fixes in the report
This commit is contained in:
1 parent
199a5efaef
commit
22887fef03
100 files changed
+9740
-429
No files matched your search
@@ -110,3 +110,43 @@ func TestSetBaseURLIgnoresBlank(t *testing.T) {
|
||||
t.Fatalf("SetBaseURL(blank) changed baseURL to %q, want unchanged", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithClientIPSendsXForwardedForOnCredentialCalls(t *testing.T) {
|
||||
var seen []string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
seen = append(seen, r.Header.Get(ForwardedForHeader))
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write([]byte(`{"user":{"id":1,"username":"a"}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
client := New(server.URL)
|
||||
|
||||
ctx := WithClientIP(context.Background(), " 203.0.113.9 ")
|
||||
if _, err := client.Login(ctx, "a", "password123", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := client.Register(WithClientIP(context.Background(), "2001:db8::1"), "a", "a@b.com", "password123"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := client.TOTPVerify(ctx, "tok", "123456"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// No address, and values that are not IP addresses, send no header.
|
||||
if _, err := client.Login(context.Background(), "a", "password123", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, bad := range []string{"", "not-an-ip", "203.0.113.9\r\nX-Evil: 1"} {
|
||||
if _, err := client.Login(WithClientIP(context.Background(), bad), "a", "password123", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
want := []string{"203.0.113.9", "2001:db8::1", "203.0.113.9", "", "", "", ""}
|
||||
if len(seen) != len(want) {
|
||||
t.Fatalf("server saw %d requests, want %d", len(seen), len(want))
|
||||
}
|
||||
for i := range want {
|
||||
if seen[i] != want[i] {
|
||||
t.Errorf("request %d X-Forwarded-For = %q, want %q", i, seen[i], want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user