|
|
@@ -2,7 +2,6 @@ package api_test
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
- "fmt"
|
|
|
"net/http"
|
|
|
"net/http/httptest"
|
|
|
"reflect"
|
|
|
@@ -96,12 +95,12 @@ func newTester(canQuery bool) *tester {
|
|
|
appConf := config.Conf{
|
|
|
Debug: true,
|
|
|
Server: config.ServerConf{
|
|
|
- Port: 8080,
|
|
|
- CookieName: "porter",
|
|
|
- CookieSecrets: [][]byte{[]byte("secret")},
|
|
|
- TimeoutRead: time.Second * 5,
|
|
|
- TimeoutWrite: time.Second * 10,
|
|
|
- TimeoutIdle: time.Second * 15,
|
|
|
+ Port: 8080,
|
|
|
+ CookieName: "porter",
|
|
|
+ CookieSecret: []byte("secret"),
|
|
|
+ TimeoutRead: time.Second * 5,
|
|
|
+ TimeoutWrite: time.Second * 10,
|
|
|
+ TimeoutIdle: time.Second * 15,
|
|
|
},
|
|
|
// unimportant here
|
|
|
Db: config.DBConf{},
|
|
|
@@ -607,7 +606,46 @@ var updateUserTests = []*userTest{
|
|
|
json.Unmarshal(rr2.Body.Bytes(), gotBody)
|
|
|
json.Unmarshal([]byte(`{"id":1,"email":"belanger@getporter.dev","clusters":[{"name":"cluster-test","server":"https://localhost","context":"context-test","user":"test-admin"}],"rawKubeConfig":"apiVersion: v1\nkind: Config\npreferences: {}\ncurrent-context: context-test\nclusters:\n- cluster:\n server: https://localhost\n name: cluster-test\ncontexts:\n- context:\n cluster: cluster-test\n user: test-admin\n name: context-test\nusers:\n- name: test-admin"}`), expBody)
|
|
|
|
|
|
- fmt.Println(gotBody.Clusters[0], expBody.Clusters[0])
|
|
|
+ if !reflect.DeepEqual(gotBody, expBody) {
|
|
|
+ t.Errorf("%s, handler returned wrong body: got %v want %v",
|
|
|
+ "validator failed", gotBody, expBody)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ &userTest{
|
|
|
+ initializers: []func(tester *tester){
|
|
|
+ initUserWithClusters,
|
|
|
+ },
|
|
|
+ msg: "Update user successful without rawKubeConfig",
|
|
|
+ method: "PUT",
|
|
|
+ endpoint: "/api/users/1",
|
|
|
+ body: `{"allowedClusters":[]}`,
|
|
|
+ expStatus: http.StatusNoContent,
|
|
|
+ expBody: "",
|
|
|
+ useCookie: true,
|
|
|
+ validators: []func(c *userTest, tester *tester, t *testing.T){
|
|
|
+ func(c *userTest, tester *tester, t *testing.T) {
|
|
|
+ req, err := http.NewRequest(
|
|
|
+ "GET",
|
|
|
+ "/api/users/1",
|
|
|
+ strings.NewReader(""),
|
|
|
+ )
|
|
|
+
|
|
|
+ req.AddCookie(tester.cookie)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ rr2 := httptest.NewRecorder()
|
|
|
+ tester.router.ServeHTTP(rr2, req)
|
|
|
+
|
|
|
+ gotBody := &models.UserExternal{}
|
|
|
+ expBody := &models.UserExternal{}
|
|
|
+
|
|
|
+ json.Unmarshal(rr2.Body.Bytes(), gotBody)
|
|
|
+ json.Unmarshal([]byte(`{"id":1,"email":"belanger@getporter.dev","clusters":[],"rawKubeConfig":"apiVersion: v1\nkind: Config\npreferences: {}\ncurrent-context: context-test\nclusters:\n- cluster:\n server: https://localhost\n name: cluster-test\ncontexts:\n- context:\n cluster: cluster-test\n user: test-admin\n name: context-test\nusers:\n- name: test-admin"}`), expBody)
|
|
|
|
|
|
if !reflect.DeepEqual(gotBody, expBody) {
|
|
|
t.Errorf("%s, handler returned wrong body: got %v want %v",
|