Skip to content

Commit

Permalink
test: update engine tests #2710
Browse files Browse the repository at this point in the history
  • Loading branch information
jgomer2001 committed Oct 25, 2022
1 parent 35bd980 commit dd68b91
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.jans.agama.test;

import com.gargoylesoftware.htmlunit.html.HtmlPage;

import org.testng.annotations.Test;

import static org.testng.Assert.*;

public class InexistentFlowTest extends BaseTest {

@Test
public void test() {
HtmlPage page = launch("flow" + Math.random(), null);
assertFalse(page.getUrl().toString().endsWith(".fls"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import static org.testng.Assert.*;

@org.testng.annotations.Ignore
public class MathFlowTest extends BaseTest {

private static final String QNAME = "io.jans.agama.test.math";
Expand Down
33 changes: 14 additions & 19 deletions agama/engine/src/test/java/io/jans/agama/test/UidOnlyAuthTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.jans.agama.test;

import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
Expand All @@ -26,27 +24,24 @@ public void enableJS() {
@Test
public void randUid() {

HtmlPage page = start("" + Math.random());
page = proceed(page);
assertOK(page);
start("" + Math.random());
HtmlPage page = (HtmlPage) currentPageAfter(2000);

assertOK(page);
assertTrue(page.getUrl().toString().endsWith("error.htm"));
assertTextContained(page.getVisibleText().toLowerCase(), "failed", "authenticate");

}

@Test(dependsOnMethods = "randUid", alwaysRun = true)
@Parameters("redirectUri")
public void adminUid(String redirectUri) {

HtmlPage page = start("admin");
page = proceed(page);
start("admin");
Page page = currentPageAfter(2000);

assertOK(page);

if (!page.getUrl().toString().startsWith(redirectUri)) {
//check if this is the consent page
assertTextContained(page.getVisibleText().toLowerCase(), "permission", "allow");
}
assertTrue(page.getUrl().toString().startsWith(redirectUri));

}

Expand All @@ -59,15 +54,15 @@ private HtmlPage start(String uid) {

}

private HtmlPage proceed(HtmlPage page) {
private Page currentPageAfter(long wait) {

try {
//wait for the auto-submitting javascript to execute (see finished.ftlh) and redirections to take place
Thread.sleep(2000);
page = (HtmlPage) client.getCurrentWindow().getEnclosedPage();
Thread.sleep(wait);
Page p = client.getCurrentWindow().getEnclosedPage();

logger.debug("Landed at {}",page.getUrl());
return page;
logger.debug("Landed at {}", p.getUrl());
return p;
} catch (Exception e) {
fail(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ small = Call java.lang.Math#decrementExact small

Repeat small times max
divisor = Call java.lang.Math#incrementExact divisor
k = 0

//Try to divide the numbers by 2, 3, ... small+1
Iterate over numbers using n
k = Iterate over numbers using n
modulus = Call java.lang.Math#floorMod n divisor
Quit When modulus is 0
k = Call java.lang.Math#incrementExact k

Quit When k is numbers.length

Expand Down
2 changes: 1 addition & 1 deletion agama/engine/src/test/resources/testng.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

authzEndpoint=${server}/jans-auth/restv1/authorize

redirectUri=${server}/admin-ui
redirectUri=${server}/.well-known/openid-configuration

clientId=${clientId}

Expand Down
6 changes: 6 additions & 0 deletions agama/engine/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,10 @@
</classes>
</test>

<test name="inexistent" enabled="false">
<classes>
<class name="io.jans.agama.test.InexistentFlowTest" />
</classes>
</test>

</suite>

0 comments on commit dd68b91

Please sign in to comment.