Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-go-1.22
Browse files Browse the repository at this point in the history
  • Loading branch information
friedrichg authored Jun 10, 2024
2 parents f6157af + 2c53fa7 commit eec746c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions gateway/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Tenant struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
ID string `yaml:"id"`
Passthrough bool `yaml:"passthrough"`
}

func Init(filePath string) (Config, error) {
Expand Down
31 changes: 31 additions & 0 deletions gateway/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func TestStartGateway(t *testing.T) {
testCases := []struct {
name string
authHeader string
orgID string
config *Config
paths []string
expectedStatus int
Expand Down Expand Up @@ -220,6 +221,31 @@ func TestStartGateway(t *testing.T) {
authHeader: "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password")),
expectedStatus: http.StatusOK,
},
{
name: "passthrough config",
config: &Config{
Tenants: []Tenant{
{
Authentication: "basic",
Username: "username",
Password: "password",
Passthrough: true,
},
},
Distributor: Upstream{
URL: distributorServer.URL,
Paths: []string{
"/test/distributor",
},
},
},
paths: []string{
"/test/distributor",
},
authHeader: "Basic " + base64.StdEncoding.EncodeToString([]byte("username:password")),
orgID: "orgID",
expectedStatus: http.StatusOK,
},
{
name: "not found route",
config: &Config{
Expand Down Expand Up @@ -348,6 +374,11 @@ func TestStartGateway(t *testing.T) {
for _, path := range tc.paths {
req, _ := http.NewRequest("GET", mockServer.URL+path, nil)
req.Header.Set("Authorization", tc.authHeader)

if tc.orgID != "" {
req.Header.Set("X-Scope-OrgID", tc.orgID)
}

resp, err := client.Do(req)
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 3 additions & 1 deletion gateway/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func (tenant *Tenant) basicAuth(w http.ResponseWriter, r *http.Request) bool {
return false
}

r.Header.Set("X-Scope-OrgID", tenant.ID)
if !tenant.Passthrough {
r.Header.Set("X-Scope-OrgID", tenant.ID)
}
return true
}

Expand Down

0 comments on commit eec746c

Please sign in to comment.