-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
* Add middleware * Add frontend * Add unit test * Add license and update go mod * vendor * Fix linting * lint * Remove unneeded comments
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package middleware | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
|
||
"github.com/Azure/msi-dataplane/pkg/dataplane" | ||
) | ||
|
||
const ( | ||
mockIdentityURL = "https://bogus.identity.azure-int.net/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/rg/providers/Microsoft.ApiManagement/service/test/credentials?tid=00000000-0000-0000-0000-000000000000&oid=00000000-0000-0000-0000-000000000000&aid=00000000-0000-0000-0000-000000000000" | ||
mockTenantIDEnvVar = "MOCK_MSI_TENANT_ID" | ||
) | ||
|
||
func MockMSIMiddleware(h http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
r.Header.Set(dataplane.MsiIdentityURLHeader, mockIdentityURL) | ||
r.Header.Set(dataplane.MsiTenantHeader, os.Getenv(mockTenantIDEnvVar)) | ||
h.ServeHTTP(w, r) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package middleware | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the Apache License 2.0. | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/Azure/msi-dataplane/pkg/dataplane" | ||
) | ||
|
||
func TestMockMSIMiddleware(t *testing.T) { | ||
mockTenantID := "test-tenant-id" | ||
t.Setenv(mockTenantIDEnvVar, mockTenantID) | ||
|
||
mockHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}) | ||
handler := MockMSIMiddleware(mockHandler) | ||
|
||
req := httptest.NewRequest(http.MethodGet, "http://example.com", nil) | ||
rr := httptest.NewRecorder() | ||
|
||
handler.ServeHTTP(rr, req) | ||
|
||
if req.Header.Get(dataplane.MsiIdentityURLHeader) != mockIdentityURL { | ||
t.Errorf("Expected %s, got %s", mockIdentityURL, req.Header.Get(dataplane.MsiIdentityURLHeader)) | ||
} | ||
if req.Header.Get(dataplane.MsiTenantHeader) != mockTenantID { | ||
t.Errorf("Expected %s, got %s", mockTenantID, req.Header.Get(dataplane.MsiTenantHeader)) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.