This is an automated email from the ASF dual-hosted git repository.

rawlin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit c18d535022fef2ab8b893851e3e811c5427aa540
Author: Rawlin Peters <[email protected]>
AuthorDate: Fri Aug 30 14:43:05 2019 -0600

    add tests
---
 traffic_ops/testing/api/v14/loginfail_test.go      |  9 ++++++
 traffic_ops/traffic_ops_golang/login/login_test.go | 32 +++++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/traffic_ops/testing/api/v14/loginfail_test.go 
b/traffic_ops/testing/api/v14/loginfail_test.go
index 36264b9..71bc226 100644
--- a/traffic_ops/testing/api/v14/loginfail_test.go
+++ b/traffic_ops/testing/api/v14/loginfail_test.go
@@ -30,6 +30,7 @@ import (
 func TestLoginFail(t *testing.T) {
        WithObjs(t, []TCObj{CDNs}, func() {
                PostTestLoginFail(t)
+               LoginWithEmptyCredentialsTest(t)
        })
 }
 
@@ -59,6 +60,14 @@ func PostTestLoginFail(t *testing.T) {
        }
 }
 
+func LoginWithEmptyCredentialsTest(t *testing.T) {
+       userAgent := "to-api-v14-client-tests-loginfailtest"
+       _, _, err := toclient.LoginWithAgent(Config.TrafficOps.URL, 
Config.TrafficOps.Users.Admin, "", true, userAgent, false, 
time.Second*time.Duration(Config.Default.Session.TimeoutInSecs))
+       if err == nil {
+               t.Fatalf("expected error when logging in with empty 
credentials, actual nil")
+       }
+}
+
 func getUninitializedTOClient(user, pass, uri, agent string, reqTimeout 
time.Duration) (*toclient.Session, error) {
        insecure := true
        useCache := false
diff --git a/traffic_ops/traffic_ops_golang/login/login_test.go 
b/traffic_ops/traffic_ops_golang/login/login_test.go
index cd522a8..15f8700 100644
--- a/traffic_ops/traffic_ops_golang/login/login_test.go
+++ b/traffic_ops/traffic_ops_golang/login/login_test.go
@@ -19,7 +19,37 @@ package login
  * under the License.
  */
 
-import "testing"
+import (
+       "net/http"
+       "net/http/httptest"
+       "strings"
+       "testing"
+
+       "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/config"
+)
+
+func TestLoginWithEmptyCredentials(t *testing.T) {
+       testInputs := []string{
+               `{"u":"","p":""}`,
+               `{"u":"foo","p":""}`,
+               `{"u":"","p":"foo"}`,
+       }
+
+       for _, testInput := range testInputs {
+               w := httptest.NewRecorder()
+               body := strings.NewReader(testInput)
+               r, err := http.NewRequest(http.MethodPost, "login", body)
+               if err != nil {
+                       t.Error("Error creating new request")
+               }
+               LoginHandler(nil, config.Config{})(w, r)
+
+               expected := `{"alerts":[{"text":"username and password are 
required","level":"error"}]}`
+               if w.Body.String() != expected {
+                       t.Error("Expected body", expected, "got", 
w.Body.String())
+               }
+       }
+}
 
 func TestVerifyUrlOnWhiteList(t *testing.T) {
        type TestResult struct {

Reply via email to