forked from github/wulkanowy-mirror
New login UI (#29)
* Refactor activity names * Refactor login activity and async task * Add forgot password and create account links * Login without passing symbol in login form * Add heading text before login form * Refactor API/login * Add login loading steps * Remove unnecessary try catch * Refactor snp and add tests * Remove redudant throws clauses
This commit is contained in:
@ -31,12 +31,46 @@ public class VulcanTest extends Vulcan {
|
||||
.thenReturn(snp);
|
||||
}
|
||||
|
||||
@Test(expected = NotLoggedInErrorException.class)
|
||||
@Test
|
||||
public void getStudentAndParentTest() throws Exception {
|
||||
Cookies cookies = new Cookies();
|
||||
|
||||
Vulcan vulcan = Mockito.mock(Vulcan.class);
|
||||
Mockito.when(vulcan.getCookiesObject()).thenReturn(cookies);
|
||||
|
||||
StudentAndParent snp = Mockito.mock(StudentAndParent.class);
|
||||
Mockito.doNothing().when(snp).storeContextCookies();
|
||||
Mockito.when(snp.getCookiesObject()).thenReturn(cookies);
|
||||
Mockito.when(vulcan.createSnp( // nullable because method uses class vars, refactor?
|
||||
Mockito.nullable(Cookies.class), Mockito.nullable(String.class), Mockito.nullable(String.class)
|
||||
)).thenReturn(snp);
|
||||
|
||||
Mockito.when(vulcan.getStudentAndParent()).thenCallRealMethod();
|
||||
|
||||
StudentAndParent vulcanSnP = vulcan.getStudentAndParent();
|
||||
|
||||
Assert.assertEquals(snp, vulcanSnP);
|
||||
Assert.assertEquals(vulcanSnP, vulcan.getStudentAndParent());
|
||||
}
|
||||
|
||||
@Test(expected = NotLoggedInErrorException.class)
|
||||
public void getStudentAndParentNotLoggedInTest() throws Exception {
|
||||
Mockito.when(vulcan.getStudentAndParent()).thenCallRealMethod();
|
||||
vulcan.getStudentAndParent();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSnPTest() throws Exception {
|
||||
Vulcan vulcan = new Vulcan();
|
||||
vulcan.login(new Cookies(), "testSymbol");
|
||||
|
||||
Assert.assertThat(vulcan.createSnp(new Cookies(), "testSymbol", null),
|
||||
CoreMatchers.instanceOf(StudentAndParent.class));
|
||||
|
||||
Assert.assertThat(vulcan.createSnp(new Cookies(), "testSymbol", "testId"),
|
||||
CoreMatchers.instanceOf(StudentAndParent.class));
|
||||
}
|
||||
|
||||
@Test(expected = NotLoggedInErrorException.class)
|
||||
public void getAttendanceExceptionText() throws Exception {
|
||||
Mockito.when(vulcan.getAttendanceTable()).thenCallRealMethod();
|
||||
|
@ -1,13 +1,126 @@
|
||||
package io.github.wulkanowy.api.login;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import io.github.wulkanowy.api.Cookies;
|
||||
import io.github.wulkanowy.api.FixtureHelper;
|
||||
|
||||
public class LoginTest {
|
||||
|
||||
public String getFixtureAsString(String fixtureFileName) {
|
||||
return FixtureHelper.getAsString(getClass().getResourceAsStream(fixtureFileName));
|
||||
}
|
||||
|
||||
public Login getSetUpLogin(String fixtureFileName) throws Exception {
|
||||
Document tablePageDocument = Jsoup.parse(getFixtureAsString(fixtureFileName));
|
||||
|
||||
Login login = Mockito.mock(Login.class);
|
||||
Mockito.when(login.postPageByUrl(Mockito.anyString(), Mockito.any(String[][].class))
|
||||
).thenReturn(tablePageDocument);
|
||||
Mockito.when(login.getLoginPageUrl()).thenReturn("");
|
||||
Mockito.when(login.getLoginEndpointPageUrl()).thenReturn("asdf");
|
||||
return login;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void login() throws Exception {
|
||||
assertEquals(4, 2 + 2);
|
||||
public void loginTest() throws Exception {
|
||||
Login login = getSetUpLogin("Logowanie-success.html");
|
||||
Mockito.when(login.login(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))
|
||||
.thenCallRealMethod();
|
||||
Mockito.when(login.sendCredentials(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))
|
||||
.thenReturn("<xml>");
|
||||
Mockito.when(login.sendCertificate(Mockito.anyString(), Mockito.anyString())).thenReturn("d123");
|
||||
Assert.assertEquals("d123", login.login("a@a", "pswd", "d123"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loginDefaultTest() throws Exception {
|
||||
Login login = getSetUpLogin("Logowanie-success.html");
|
||||
Mockito.when(login.getLoginEndpointPageUrl()).thenReturn("asdf");
|
||||
Mockito.when(login.login(Mockito.anyString(), Mockito.anyString(), Mockito.anyString()))
|
||||
.thenCallRealMethod();
|
||||
Mockito.when(login.sendCredentials(Mockito.anyString(), Mockito.anyString(), Mockito.eq("Default")))
|
||||
.thenReturn(getFixtureAsString("cert.xml"));
|
||||
Mockito.when(login.findSymbol(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
Mockito.when(login.sendCertificate(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
Mockito.when(login.findSymbolInCertificate(Mockito.anyString())).thenCallRealMethod();
|
||||
Assert.assertEquals("demo12345", login.login("a@a", "pswd", "Default"));
|
||||
}
|
||||
|
||||
@Test(expected = BadCredentialsException.class)
|
||||
public void sendWrongCredentialsTest() throws Exception {
|
||||
Login login = getSetUpLogin("Logowanie-error.html");
|
||||
Mockito.when(login.sendCredentials(
|
||||
Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
|
||||
login.sendCredentials("a@a", "pswd", "d123");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendCredentialsCertificateTest() throws Exception {
|
||||
Login login = getSetUpLogin("Logowanie-certyfikat.html");
|
||||
Mockito.when(login.sendCredentials(
|
||||
Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
Mockito.when(login.getLoginPageUrl()).thenReturn("http://a.a");
|
||||
|
||||
Assert.assertEquals(
|
||||
getFixtureAsString("cert.xml").replaceAll("\\s+",""),
|
||||
login.sendCredentials("a@a", "passwd", "d123").replaceAll("\\s+","")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendCertificateNotDefaultSymbolSuccessTest() throws Exception {
|
||||
Login login = getSetUpLogin("Logowanie-success.html");
|
||||
Mockito.when(login.findSymbol(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
Mockito.when(login.sendCertificate(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
Assert.assertEquals("wulkanowyschool321", login.sendCertificate("", "wulkanowyschool321"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendCertificateDefaultSymbolSuccessTest() throws Exception {
|
||||
Login login = getSetUpLogin("Logowanie-success.html");
|
||||
Mockito.when(login.findSymbol(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
Mockito.when(login.findSymbolInCertificate(Mockito.anyString())).thenCallRealMethod();
|
||||
Mockito.when(login.sendCertificate(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
Assert.assertEquals("demo12345",
|
||||
login.sendCertificate(getFixtureAsString("cert.xml"), "Default"));
|
||||
}
|
||||
|
||||
@Test(expected = AccountPermissionException.class)
|
||||
public void sendCertificateAccountPermissionTest() throws Exception {
|
||||
Login login = getSetUpLogin("Logowanie-brak-dostepu.html");
|
||||
Mockito.when(login.findSymbol(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
Mockito.when(login.sendCertificate(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
login.sendCertificate(getFixtureAsString("cert.xml"), "demo123");
|
||||
}
|
||||
|
||||
@Test(expected = LoginErrorException.class)
|
||||
public void sendCertificateLoginErrorTest() throws Exception {
|
||||
Login login = getSetUpLogin("Logowanie-certyfikat.html"); // change to other document
|
||||
Mockito.when(login.findSymbol(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
Mockito.when(login.sendCertificate(Mockito.anyString(), Mockito.anyString())).thenCallRealMethod();
|
||||
login.sendCertificate(getFixtureAsString("cert.xml"), "demo123");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findSymbolInCertificateTest() throws Exception {
|
||||
Login login = new Login(new Cookies());
|
||||
|
||||
String certificate = getFixtureAsString("cert.xml");
|
||||
|
||||
Assert.assertEquals("demo12345", login.findSymbolInCertificate(certificate));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findSymbolInInvalidCertificateTest() throws Exception {
|
||||
Login login = new Login(new Cookies());
|
||||
|
||||
Assert.assertEquals("", login.findSymbolInCertificate("<xml></xml>")); // change to real cert with empty symbols
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Logowanie</title>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1">
|
||||
<div>
|
||||
Adres <b>example@wulkanowy.io</b> nie został zarejestrowany w dzienniku uczniowskim jako adres rodzica, bądź ucznia.
|
||||
Jeśli jesteś rodzicem (prawnym opiekunem) ucznia (lub uczniem) szkoły korzystającej z dziennika „UONET +” udaj się do
|
||||
wychowawcy i poproś o wprowadzenie Twojego adresu e-mail do Twoich danych.
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,17 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Working...</title>
|
||||
</head>
|
||||
<body>
|
||||
<form method="POST" name="hiddenform" action="https://fake-log.com/Default/LoginEndpoint.aspx">
|
||||
<input type="hidden" name="wa" value="wsignin1.0">
|
||||
<input type="hidden" name="wresult" value="<trust:RequestSecurityTokenResponseCollection xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512"><trust:RequestSecurityTokenResponse Context="https://uonetplus.fake-log.com/Default/LoginEndpoint.aspx"><trust:RequestedSecurityToken><saml:Assertion AssertionID="_12345678-1234-1234-1234-1234567890ab" IssueInstant="2017-10-18T22:00:29.006Z" Issuer="CUFSTokenService" MajorVersion="1" MinorVersion="1" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion"><saml:AttributeStatement><saml:Attribute AttributeName="UserInstance" AttributeNamespace="http://schemas.fake-log.com/ws/identity/claims"><saml:AttributeValue>Default</saml:AttributeValue><saml:AttributeValue>demo12345</saml:AttributeValue><saml:AttributeValue>incorrect value</saml:AttributeValue><saml:AttributeValue>warszawa</saml:AttributeValue><saml:AttributeValue>asdf</saml:AttributeValue><saml:AttributeValue>asdfsdf</saml:AttributeValue></saml:Attribute></saml:AttributeStatement></saml:Assertion></trust:RequestedSecurityToken></trust:RequestSecurityTokenResponse></trust:RequestSecurityTokenResponseCollection>">
|
||||
<input type="hidden" name="wctx" value="https://fake-log.com/Default/LoginEndpoint.aspx">
|
||||
<noscript>
|
||||
<p>Script is disabled. Click Submit to continue.</p>
|
||||
<input type="submit" value="Submit">
|
||||
</noscript>
|
||||
</form>
|
||||
<script language="javascript">window.setTimeout('document.forms[0].submit()', 0);</script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,18 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Logowanie (demo123)</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="MainDiv">
|
||||
<form>
|
||||
<div class="ErrorMessage center">
|
||||
Zła nazwa użytkownika lub hasło
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div id="globalfooter">
|
||||
<div id="left">16.2.0.4450</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,16 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Uonet+</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="startScreen">
|
||||
<div class="topBar">
|
||||
<div class="panelTopBar">
|
||||
<span class="userdata">example@wulkanowy.io (<a href="/demo123/LoginEndpoint.aspx?logout=true">wyloguj</a>)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,18 @@
|
||||
<trust:RequestSecurityTokenResponseCollection xmlns:trust="http://docs.oasis-open.org/ws-sx/ws-trust/200512">
|
||||
<trust:RequestSecurityTokenResponse Context="https://uonetplus.fake-log.com/Default/LoginEndpoint.aspx">
|
||||
<trust:RequestedSecurityToken>
|
||||
<saml:Assertion AssertionID="_12345678-1234-1234-1234-1234567890ab" IssueInstant="2017-10-18T22:00:29.006Z" Issuer="CUFSTokenService" MajorVersion="1" MinorVersion="1" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">
|
||||
<saml:AttributeStatement>
|
||||
<saml:Attribute AttributeName="UserInstance" AttributeNamespace="http://schemas.fake-log.com/ws/identity/claims">
|
||||
<saml:AttributeValue>Default</saml:AttributeValue>
|
||||
<saml:AttributeValue>demo12345</saml:AttributeValue>
|
||||
<saml:AttributeValue>incorrect value</saml:AttributeValue>
|
||||
<saml:AttributeValue>warszawa</saml:AttributeValue>
|
||||
<saml:AttributeValue>asdf</saml:AttributeValue>
|
||||
<saml:AttributeValue>asdfsdf</saml:AttributeValue>
|
||||
</saml:Attribute>
|
||||
</saml:AttributeStatement>
|
||||
</saml:Assertion>
|
||||
</trust:RequestedSecurityToken>
|
||||
</trust:RequestSecurityTokenResponse>
|
||||
</trust:RequestSecurityTokenResponseCollection>
|
Reference in New Issue
Block a user