Просмотр исходного кода

just some updated tests for auth check, login, and register ya know

sunguroku 5 лет назад
Родитель
Сommit
fc29a12f08
6 измененных файлов с 61 добавлено и 133 удалено
  1. 0 1
      dashboard/src/main/Main.tsx
  2. 1 1
      docker/.env
  3. 20 2
      docs/API.md
  4. 0 1
      server/api/user_handler.go
  5. 40 4
      server/api/user_handler_test.go
  6. 0 124
      test.yaml

+ 0 - 1
dashboard/src/main/Main.tsx

@@ -30,7 +30,6 @@ export default class Main extends Component<PropsType, StateType> {
 
   componentDidMount() {
     let { setUserId } = this.context;
-    console.log('how')
     api.checkAuth('', {}, {}, (err: any, res: any) => {
       if (res.data) {
         setUserId(res.data.id)

+ 1 - 1
docker/.env

@@ -12,4 +12,4 @@ DB_PASS=porter
 DB_NAME=porter
 COOKIE_SECRETS=secret
 
-QUICK_START=false
+QUICK_START=true

+ 20 - 2
docs/API.md

@@ -207,7 +207,16 @@ User{
 }
 ```
 
-**Successful Response Body**: N/A
+**Successful Response Body**:
+User object with only the id field. Other fields are empty - with values in parantheses.
+```js
+{
+  "id": Int,
+  "email": String ("")
+  "contexts": []String (NULL)
+  "rawKubeConfig": String ("")
+}
+```
 
 **Successful Status Code**: `201`
 
@@ -260,7 +269,16 @@ User{
 }
 ```
 
-**Successful Response Body**: N/A
+**Successful Response Body**:
+User object with only the id field. Other fields are empty - with values in parantheses.
+```js
+{
+  "id": Int,
+  "email": String ("")
+  "contexts": []String (NULL)
+  "rawKubeConfig": String ("")
+}
+```
 
 **Successful Status Code**: `200`
 

+ 0 - 1
server/api/user_handler.go

@@ -343,7 +343,6 @@ func (app *App) sendUserID(w http.ResponseWriter, userID uint) error {
 	resUser := &models.UserExternal{
 		ID: userID,
 	}
-
 	if err := json.NewEncoder(w).Encode(resUser); err != nil {
 		return err
 	}

+ 40 - 4
server/api/user_handler_test.go

@@ -70,6 +70,42 @@ func testUserRequests(t *testing.T, tests []*userTest, canQuery bool) {
 
 // ------------------------- TEST FIXTURES AND FUNCTIONS  ------------------------- //
 
+var authCheckTests = []*userTest{
+	&userTest{
+		initializers: []func(tester *tester){
+			initUserDefault,
+		},
+		msg:       "Auth check successful. User is logged in.",
+		method:    "GET",
+		endpoint:  "/api/auth/check",
+		expStatus: http.StatusOK,
+		body:      "",
+		expBody:   `{"id":1,"email":"","contexts":null,"rawKubeConfig":""}`,
+		useCookie: true,
+		validators: []func(c *userTest, tester *tester, t *testing.T){
+			userBasicBodyValidator,
+		},
+	},
+	&userTest{
+		initializers: []func(tester *tester){
+			initUserDefault,
+		},
+		msg:       "Auth check failure. User is not logged in.",
+		method:    "GET",
+		endpoint:  "/api/auth/check",
+		body:      "",
+		expStatus: http.StatusForbidden,
+		expBody:   http.StatusText(http.StatusForbidden) + "\n",
+		validators: []func(c *userTest, tester *tester, t *testing.T){
+			userBasicBodyValidator,
+		},
+	},
+}
+
+func TestHandleAuthCheck(t *testing.T) {
+	testUserRequests(t, authCheckTests, true)
+}
+
 var createUserTests = []*userTest{
 	&userTest{
 		msg:      "Create user",
@@ -80,7 +116,7 @@ var createUserTests = []*userTest{
 			"password": "hello"
 		}`,
 		expStatus: http.StatusCreated,
-		expBody:   "",
+		expBody:   `{"id":1,"email":"","contexts":null,"rawKubeConfig":""}`,
 	},
 	&userTest{
 		msg:      "Create user invalid email",
@@ -180,7 +216,7 @@ var loginUserTests = []*userTest{
 			"password": "hello"
 		}`,
 		expStatus: http.StatusOK,
-		expBody:   ``,
+		expBody:   `{"id":1,"email":"","contexts":null,"rawKubeConfig":""}`,
 		validators: []func(c *userTest, tester *tester, t *testing.T){
 			userBasicBodyValidator,
 		},
@@ -197,7 +233,7 @@ var loginUserTests = []*userTest{
 			"password": "hello"
 		}`,
 		expStatus: http.StatusOK,
-		expBody:   ``,
+		expBody:   `{"id":1,"email":"","contexts":null,"rawKubeConfig":""}`,
 		useCookie: true,
 		validators: []func(c *userTest, tester *tester, t *testing.T){
 			userBasicBodyValidator,
@@ -670,7 +706,7 @@ func initUserWithContexts(tester *tester) {
 }
 
 func userBasicBodyValidator(c *userTest, tester *tester, t *testing.T) {
-	if body := tester.rr.Body.String(); body != c.expBody {
+	if body := tester.rr.Body.String(); strings.TrimSpace(body) != strings.TrimSpace(c.expBody) {
 		t.Errorf("%s, handler returned wrong body: got %v want %v",
 			c.msg, body, c.expBody)
 	}

Разница между файлами не показана из-за своего большого размера
+ 0 - 124
test.yaml


Некоторые файлы не были показаны из-за большого количества измененных файлов