github.com/verrazzano/verrazzano@v1.7.0/authproxy/internal/testutil/testserver/server.go (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package testserver 5 6 import ( 7 "encoding/json" 8 "fmt" 9 "net/http" 10 "net/http/httptest" 11 "testing" 12 13 "github.com/stretchr/testify/assert" 14 ) 15 16 type testProviderJSON struct { 17 Issuer string `json:"issuer"` 18 } 19 20 // FakeOIDCProviderServer returns a server that handles requests to set up an OIDC provider 21 func FakeOIDCProviderServer(t *testing.T) *httptest.Server { 22 return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { 23 provider := testProviderJSON{ 24 Issuer: fmt.Sprintf("http://%s", req.Host), 25 } 26 27 providerJSON, err := json.Marshal(provider) 28 assert.NoError(t, err) 29 30 _, err = w.Write(providerJSON) 31 assert.NoError(t, err) 32 })) 33 }