Allocate mux in master.New()

Callsites no longer allocate a mux.
Master now exposes method to install handlers
which use the master's auth code.  Not used
but forks (openshift) are expected to use these
methods.  These methods will later be a point
for additional plug-in functionality.
Integration tests now use the master-provided
handler which has auth, rather than using the mux,
which didn't.  Fix TestWhoAmI now that /_whoami
sits behind auth.
This commit is contained in:
Eric Tune
2014-10-28 13:02:19 -07:00
parent ecdf65f4b1
commit 9713b58caa
5 changed files with 65 additions and 28 deletions

View File

@@ -63,18 +63,16 @@ xyz987,bob,2
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
mux := http.NewServeMux()
master.New(&master.Config{
m := master.New(&master.Config{
EtcdHelper: helper,
Mux: mux,
EnableLogsSupport: false,
EnableUISupport: false,
APIPrefix: "/api",
TokenAuthFile: f.Name(),
})
s := httptest.NewServer(mux)
s := httptest.NewServer(m.Handler)
defer s.Close()
// TODO: also test TLS, using e.g NewUnsafeTLSTransport() and NewClientCertTLSTransport() (see pkg/client/helper.go)
@@ -84,10 +82,11 @@ xyz987,bob,2
name string
token string
expected string
succeeds bool
}{
{"Valid token", "abc123", "AUTHENTICATED AS alice"},
{"Unknown token", "456jkl", "NOT AUTHENTICATED"},
{"Empty token", "", "NOT AUTHENTICATED"},
{"Valid token", "abc123", "AUTHENTICATED AS alice", true},
{"Unknown token", "456jkl", "", false},
{"No token", "", "", false},
}
for _, tc := range testCases {
req, err := http.NewRequest("GET", s.URL+"/_whoami", nil)
@@ -101,14 +100,21 @@ xyz987,bob,2
t.Fatalf("unexpected error: %v", err)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if tc.succeeds {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
actual := string(body)
if tc.expected != actual {
t.Errorf("case: %s expected: %v got: %v", tc.name, tc.expected, actual)
}
} else {
if resp.StatusCode != http.StatusUnauthorized {
t.Errorf("case: %s expected Unauthorized, got: %v", tc.name, resp.StatusCode)
}
actual := string(body)
if tc.expected != actual {
t.Errorf("case: %s expected: %v got: %v", tc.name, tc.expected, actual)
}
}
}

View File

@@ -19,7 +19,6 @@ limitations under the License.
package integration
import (
"net/http"
"net/http/httptest"
"reflect"
"testing"
@@ -40,17 +39,14 @@ func TestClient(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
mux := http.NewServeMux()
master.New(&master.Config{
m := master.New(&master.Config{
EtcdHelper: helper,
Mux: mux,
EnableLogsSupport: false,
EnableUISupport: false,
APIPrefix: "/api",
})
s := httptest.NewServer(mux)
s := httptest.NewServer(m.Handler)
testCases := []string{
"v1beta1",