Exemplo n.º 1
0
func Test_Register_AlreadyRegistered(t *testing.T) {

	SubmitRegistration(userOne, t)
	webdriver.WaitFor(5*time.Second, webdriver.ElementToVanish, "div[class='selenium-flag']")

	// Case 1: non-unique email
	const emailErr = "Already associated with a user"

	msg, err := webdriver.FetchText("span[name='EmailAddrErrorMsg']")
	if err != nil {
		t.Fatalf("Failed to fetch the email error message: %s", err)
	}

	if msg != emailErr {
		t.Fatalf("Expected error \"%s\" was in fact, \"%s\"", emailErr, msg)
	}

	// Case 2: non-unique user id
	const userErr = "Not available"
	origEmailAddr := userOne.EmailAddr
	userOne.EmailAddr = "[email protected]  "

	SubmitRegistration(userOne, t)
	userOne.EmailAddr = origEmailAddr
	webdriver.WaitFor(5*time.Second, webdriver.ElementToVanish, "div[class='selenium-flag']")

	msg, err = webdriver.FetchText("span[name='UserIdErrorMsg']")
	if err != nil {
		t.Fatalf("Failed to fetch the user id error message: %s", err)
	}

	if msg != userErr {
		t.Fatalf("Expected error \"%s\" was in fact, \"%s\"", userErr, msg)
	}
}
Exemplo n.º 2
0
func RequestPasswordResetFor(inEmailAddr string, t *testing.T) {
	url := "https://plog.org:8004/#/password"
	err := webdriver.Drv.Get(url)
	if err != nil {
		t.Fatalf("Failed to load %s: %s\n", url, err)
	}
	webdriver.WaitFor(5*time.Second, webdriver.ElementToVanish, "div[class='selenium-flag']")

	// Get elements
	elements, err := webdriver.FindNamedElements([]string{"Message", "EmailAddr", "ResetPasswordButton"})
	if err != nil {
		t.Fatalf("FindNamedElements failed: %s", err)
	}

	// Fill
	elements["EmailAddr"].Clear()
	elements["EmailAddr"].SendKeys(inEmailAddr)

	// Submit
	elements["ResetPasswordButton"].Click()

	webdriver.WaitFor(5*time.Second, webdriver.ElementToVanish, "div[class='selenium-flag']")

	// Verify expected results
	actualMsg, err := webdriver.FetchText("p[name='Message']")
	if err != nil {
		t.Fatalf("Failed to fetch the main message: %s", err)
	}

	expectMsg := fmt.Sprintf("Check email (%s) for a reset token", inEmailAddr)

	if actualMsg != expectMsg {
		t.Fatalf("Expected message \"%s\", got \"%s\"", expectMsg, actualMsg)
	}
}
Exemplo n.º 3
0
// ExpectRegistrationSuccess gets call immediately after SubmitRegistration and verifies a successful registration
func ExpectRegistrationSuccess(email string, t *testing.T) {

	webdriver.WaitFor(5*time.Second, webdriver.ElementToVanish, "div[class='selenium-flag']")

	msg, err := webdriver.FetchText("p[name='Message']")
	if err != nil {
		t.Fatalf("Failed to fetch the main message: %s", err)
	}

	expectMsg := fmt.Sprintf("Registration successful. Next step: Check your %s inbox and verify your email address.", email)

	if msg != expectMsg {
		t.Fatalf("Main message did not match expected, got %s", msg)
	}
}
Exemplo n.º 4
0
func doVerifyCase(t *testing.T, cur vCase) {
	url := fmt.Sprintf("https://plog.org:8004/#/verify/%s/token/%s", cur.email, cur.tok)
	err := webdriver.Drv.Get(url)
	if err != nil {
		t.Fatalf("Failed to load %s: %s\n", url, err)
	}
	webdriver.WaitFor(5*time.Second, webdriver.ElementToVanish, "div[class='selenium-flag']")

	actualMsg, err := webdriver.FetchText("p[name='Message']")
	if err != nil {
		t.Fatalf("Failed to fetch the main message: %s", err)
	}

	if actualMsg != cur.msg {
		t.Fatalf("Expected message \"%s\", got \"%s\"", cur.msg, actualMsg)
	}
}
Exemplo n.º 5
0
func Test_Login_table(t *testing.T) {

	cases := []loginCase{
		{"UserId", Login{"no such dude", "passwordpassword"}, "Authentication failed", "absent"},
		{"UserId", Login{"wrong uid", userOne.ClearPassword}, "Authentication failed", "absent"},
		{"UserId", Login{userOne.UserId, "wrong password"}, "Authentication failed", "absent"},
		{"UserId", Login{userOne.UserId, userOne.ClearPassword}, "SKIP", "present"},
		// if already logged in, automatic login will happen. So for testing should log out
	}

	for c := 0; c < len(cases); c++ {
		cur := cases[c]
		t.Logf("Case %d: UserIdentifier (%s)=%s ClearPassword=%s", c, cur.idTyp, cur.lin.UserIdentifier, cur.lin.ClearPassword)

		if len(cur.lin.ClearPassword) < 10 {
			t.Fatalf("Case is not valid since ClearPassword (%s) is too short")
		}

		GotoLogin(t)
		ExpectOnLoginPage(t)
		SubmitLogin(cur.lin, t)

		webdriver.WaitFor(5*time.Second, webdriver.ElementToVanish, "div[class='selenium-flag']")

		if cur.tokc == "absent" {
			// Login failure was expected
			msg, err := webdriver.FetchText("p[name='LoginMessage']")
			if err != nil {
				t.Fatalf("Failed to fetch the main message: %s", err)
			}

			if msg != "Authentication failed" {
				t.Errorf("Expected failure message, got \"%s\"", msg)
			}

			ExpectNoSessionToken(t)
		} else {
			ExpectSessionToken(t)
		}
	}
}
Exemplo n.º 6
0
func Test_Logout(t *testing.T) {
	// happy path logout
	t.Logf("Case: happy path logout")
	Logout(t)

	// visit while logged out; expect to get login page
	// TODO add an Image URL
	pagesNeedingLogin := []string{"/#/album", "/#/album/2013-09%20September"}

	for p := 0; p < len(pagesNeedingLogin); p++ {
		page := fmt.Sprintf("https://plog.org:8004%s", pagesNeedingLogin[p])
		t.Logf("Case: %s", pagesNeedingLogin[p])

		err := webdriver.Drv.Get(page)
		if err != nil {
			t.Fatalf("Failed to load %s: %s\n", page, err)
		}

		webdriver.WaitFor(5*time.Second, webdriver.UrlIsCurrent, "https://plog.org:8004/#/login")
		if webdriver.WaitForTimedOut {
			t.Fatalf("Failed to land at expected URL")
		}

		msg, err := webdriver.FetchText("p[name='LoginMessage']")
		if err != nil {
			t.Fatalf("Failed to fetch the main message: %s", err)
		}

		if msg != "" {
			t.Errorf("Message was not blank: %s", msg)
		}

		result, err := webdriver.Drv.ExecuteScript("return localStorage['SessionToken']", nil)
		if err != nil {
			t.Fatalf("Failed to ExecuteScript: %s", err)
		}

		if result != nil {
			t.Errorf("Found a SessionToken in localStorage: %s", result)
		}

	}

	// automatic login when SessionToken is still valid: goto login, then autologin and end up on album page
	t.Logf("Case: Automatic login that works")
	GotoLogin(t)
	ExpectOnLoginPage(t)
	SubmitLogin(Login{userOne.UserId, userOne.ClearPassword}, t)

	webdriver.WaitFor(5*time.Second, webdriver.ElementToVanish, "div[class='selenium-flag']")

	ExpectSessionToken(t)

	// need to visit a page that needs login - the LogoutPageUrl page needs login
	err := webdriver.Drv.Get(LogoutPageUrl)
	if err != nil {
		t.Fatalf("Failed to load %s: %s\n", LogoutPageUrl, err)
	}

	webdriver.WaitFor(5*time.Second, webdriver.UrlIsCurrent, LogoutPageUrl)
	if webdriver.WaitForTimedOut {
		t.Fatalf("Failed to land at expected URL")
	}

	// automatic login when SessionToken is present but not valid
	t.Logf("Case: Automatic login with bad session token")

	/* This angular method does not work, need to use the document.cookie method  :(
	js := `
	  var $injector = angular.injector(['ngCookies']);
	  return $injector.invoke(function($cookies) {
	    $cookies.SessionToken = '00000000-0000-0000-dead-beef00000000';
	  });
	  `
	_, err = webdriver.Drv.ExecuteScript(js, nil)
	*/

	_, err = webdriver.Drv.ExecuteScript(`document.cookie = 'SessionToken=00000000-0000-0000-dead-beef00000000';`, nil)
	if err != nil {
		t.Fatalf("Failed to ExecuteScript: %s", err)
	}

	// need to visit a page that needs login - the LogoutPageUrl page needs login
	err = webdriver.Drv.Get(LogoutPageUrl)
	if err != nil {
		t.Fatalf("Failed to load %s: %s\n", LogoutPageUrl, err)
	}

	ExpectOnLoginPage(t)

	msg, err := webdriver.FetchText("p[name='LoginMessage']")
	if err != nil {
		t.Fatalf("Failed to fetch the login message: %s", err)
	}

	if msg != "" {
		// automatic logins don't produce "Authentication failed" messages
		t.Errorf("Expected LoginMessage to be blank, got \"%s\"", msg)
	}

	// TODO periodic re-login to extend session : Problem is how to test this without waiting 5 minutes

	// TODO login, visit page that calls loggedIn() - delete session in background - visit page that calls loggedIn() + expect it to return true - wait for background login attempt - visit page that calles loggedIn() + expect it to return false

}