Example #1
0
func (t *UserTest) TestAuthenticate() {
	structArray := generateUserStructArray()
	jsn := u.ConvertMappedStructArrayToString(u.EmbedMapUnderKey("users", structArray))

	// Create the users
	t.Post(routes.Users.Create(), JSON_CONTENT, strings.NewReader(jsn))
	t.AssertOk()
	t.AssertContentType(JSON_CONTENT)

	// Loop over the users, test with valid and invalid password
	for _, user := range structArray {
		userAuth := map[string]string{
			"email":       user["email"].(string),
			"screen_name": user["screen_name"].(string),
			"password":    user["password"].(string),
		}

		// Test with valid password
		jsn, err := json.Marshal(userAuth)
		if err != nil {
			revel.ERROR.Fatal(err)
		}
		jsonReader := strings.NewReader(string(jsn))
		t.Post(routes.Users.Authenticate(), JSON_CONTENT, jsonReader)
		t.AssertOk()
		t.AssertContentType(JSON_CONTENT)

		// Test with invalid password
		userAuth["password"] = userAuth["password"] + "1"
		jsn, err = json.Marshal(userAuth)
		if err != nil {
			revel.ERROR.Fatal(err)
		}
		jsonReader = strings.NewReader(string(jsn))
		t.Post(routes.Users.Authenticate(), JSON_CONTENT, jsonReader)
		t.AssertStatus(401)
	}
}
Example #2
0
func generateUserJson() string {
	embedded := u.EmbedMapUnderKey("users", generateUserStructArray())
	return u.ConvertMappedStructArrayToString(embedded)
}