From a90865e526d07179e3b8fad539a6d4db1f78d5b9 Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Fri, 24 Mar 2017 03:14:03 -0700 Subject: [PATCH 1/2] update login test --- tests/userlogintest.go | 60 ------------------------------------------ tests/userlogintest.sh | 20 ++++++++++++++ 2 files changed, 20 insertions(+), 60 deletions(-) delete mode 100644 tests/userlogintest.go create mode 100755 tests/userlogintest.sh diff --git a/tests/userlogintest.go b/tests/userlogintest.go deleted file mode 100644 index 5a49a8ac2b..0000000000 --- a/tests/userlogintest.go +++ /dev/null @@ -1,60 +0,0 @@ -package main - -import ( - "crypto/tls" - "flag" - "fmt" - "io/ioutil" - "net/http" - "net/url" - "strings" -) - -func main() { - usrNamePtr := flag.String("name", "anaymous", "user name") - usrPasswdPtr := flag.String("passwd", "anaymous", "user password") - flag.Parse() - - v := url.Values{} - v.Set("principal", *usrNamePtr) - v.Set("password", *usrPasswdPtr) - - body := ioutil.NopCloser(strings.NewReader(v.Encode())) //endode v:[body struce] - fmt.Println(v) - - tr := &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - } - client := &http.Client{Transport: tr} - - reqest, err := http.NewRequest("POST", "https://localhost/login", body) - if err != nil { - fmt.Println("Fatal error ", err.Error()) - } - - reqest.Header.Set("Content-Type", "application/x-www-form-urlencoded;param=value") //setting post head - - resp, err := client.Do(reqest) - defer resp.Body.Close() //close resp.Body - - fmt.Println("login status: ", resp.StatusCode) //print status code - - //content_post, err := ioutil.ReadAll(resp.Body) - //if err != nil { - // fmt.Println("Fatal error ", err.Error()) - //} - - //fmt.Println(string(content_post)) //print reply - - response, err := client.Get("https://localhost/api/logout") - if err != nil { - fmt.Println("Fatal error ", err.Error()) - } - - defer response.Body.Close() - - fmt.Println("logout status: ", resp.StatusCode) //print status code - //content_get, err := ioutil.ReadAll(response.Body) - //fmt.Println(string(content_get)) - -} diff --git a/tests/userlogintest.sh b/tests/userlogintest.sh new file mode 100755 index 0000000000..65effa495e --- /dev/null +++ b/tests/userlogintest.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +set +e + +STATUS_LOGIN=$(curl --insecure -w '%{http_code}' -d "principal=$1&password=$2" https://localhost/login) +if [ $STATUS_LOGIN -eq 200 ]; then + echo "Login Harbor success." +else + echo "Login Harbor fail." + exit 1 +fi + + +STATUS_LOGOUT=$(curl --insecure -s -o /dev/null -w '%{http_code}' https://localhost/log_out) +if [ $STATUS_LOGOUT -eq 200 ]; then + echo "Logout Harbor success." +else + echo "Logout Harbor fail." + exit 1 +fi From 8848cb8e92602e4cc1c68eb0bc5ff785e7a22f81 Mon Sep 17 00:00:00 2001 From: wy65701436 Date: Fri, 24 Mar 2017 03:50:11 -0700 Subject: [PATCH 2/2] update travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 80a1df4a73..cd7588c365 100644 --- a/.travis.yml +++ b/.travis.yml @@ -102,7 +102,7 @@ script: - docker ps - ./tests/notarytest.sh - ./tests/startuptest.sh - - go run tests/userlogintest.go -name ${HARBOR_ADMIN} -passwd ${HARBOR_ADMIN_PASSWD} + - ./tests/userlogintest.sh ${HARBOR_ADMIN} ${HARBOR_ADMIN_PASSWD} # - sudo ./tests/testprepare.sh # - go test -v ./tests/apitests