You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ra...@apache.org on 2019/08/30 21:22:09 UTC

[trafficcontrol] branch master updated (85596a0 -> c18d535)

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

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


    from 85596a0  adds blueprint directory, template and 2 examples to solicit feedback (#3884)
     new f780aff  Improve ldap error handling
     new c18d535  add tests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 traffic_ops/testing/api/v14/loginfail_test.go      |  9 ++++++
 traffic_ops/traffic_ops_golang/login/login.go      |  4 +++
 traffic_ops/traffic_ops_golang/login/login_test.go | 32 +++++++++++++++++++++-
 3 files changed, 44 insertions(+), 1 deletion(-)


[trafficcontrol] 01/02: Improve ldap error handling

Posted by ra...@apache.org.
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 f780aff77a52d52a37b4d1cc3e8e801c0b557356
Author: Rawlin Peters <ra...@comcast.com>
AuthorDate: Fri Aug 30 14:40:48 2019 -0600

    Improve ldap error handling
---
 traffic_ops/traffic_ops_golang/login/login.go | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/traffic_ops/traffic_ops_golang/login/login.go b/traffic_ops/traffic_ops_golang/login/login.go
index 07575f7..b873ef1 100644
--- a/traffic_ops/traffic_ops_golang/login/login.go
+++ b/traffic_ops/traffic_ops_golang/login/login.go
@@ -51,6 +51,10 @@ func LoginHandler(db *sqlx.DB, cfg config.Config) http.HandlerFunc {
 			handleErrs(http.StatusBadRequest, err)
 			return
 		}
+		if form.Username == "" || form.Password == "" {
+			api.HandleErr(w, r, nil, http.StatusBadRequest, errors.New("username and password are required"), nil)
+			return
+		}
 		resp := struct {
 			tc.Alerts
 		}{}


[trafficcontrol] 02/02: add tests

Posted by ra...@apache.org.
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 <ra...@comcast.com>
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 {