Merge pull request #561 from ericchiang/dev-run-server-tests-at-non-root-url

dev branch: run server tests at a non-root URL
This commit is contained in:
Eric Chiang 2016-08-19 16:45:56 -07:00 committed by GitHub
commit f219964f16

View file

@ -59,11 +59,12 @@ FDWV28nTP9sqbtsmU8Tem2jzMvZ7C/Q0AuDoKELFUpux8shm8wfIhyaPnXUGZoAZ
Np4vUwMSYV5mopESLWOg3loBxKyLGFtgGKVCjGiQvy6zISQ4fQo= Np4vUwMSYV5mopESLWOg3loBxKyLGFtgGKVCjGiQvy6zISQ4fQo=
-----END RSA PRIVATE KEY-----`) -----END RSA PRIVATE KEY-----`)
func newTestServer() (*httptest.Server, *Server) { func newTestServer(path string) (*httptest.Server, *Server) {
var server *Server var server *Server
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
server.ServeHTTP(w, r) server.ServeHTTP(w, r)
})) }))
s.URL = s.URL + path
config := Config{ config := Config{
Issuer: s.URL, Issuer: s.URL,
Storage: memory.New(), Storage: memory.New(),
@ -84,14 +85,14 @@ func newTestServer() (*httptest.Server, *Server) {
} }
func TestNewTestServer(t *testing.T) { func TestNewTestServer(t *testing.T) {
newTestServer() newTestServer("")
} }
func TestDiscovery(t *testing.T) { func TestDiscovery(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
httpServer, _ := newTestServer() httpServer, _ := newTestServer("/nonrootpath")
defer httpServer.Close() defer httpServer.Close()
p, err := oidc.NewProvider(ctx, httpServer.URL) p, err := oidc.NewProvider(ctx, httpServer.URL)
@ -117,7 +118,7 @@ func TestOAuth2Flow(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
httpServer, s := newTestServer() httpServer, s := newTestServer("/nonrootpath")
defer httpServer.Close() defer httpServer.Close()
p, err := oidc.NewProvider(ctx, httpServer.URL) p, err := oidc.NewProvider(ctx, httpServer.URL)