mirror of https://github.com/jacekkow/uphpCAS-tests

Jacek Kowalski
2015-09-05 9da16f4812a443331d93348b2b0e7a88924b6724
commit | author | age
5686c9 1 import org.junit.Test
JK 2
3 import org.openqa.selenium.WebDriver
4 import org.openqa.selenium.By
5
6 import org.junit.runner.RunWith
7 import org.junit.runners.Parameterized
8 import org.junit.runners.Parameterized.Parameter
9 import org.junit.runners.Parameterized.Parameters
10
11 import Config
12 import Common
13
14 @RunWith(Parameterized.class)
15 class StandardTests {
9da16f 16     @Parameters(name = "{0}")
5686c9 17     public static Iterable<Object[]> data() {
JK 18         return [
19             // cas, cafile, method, login page expected text, main page expected text
20             
21             // HTTP should succeed
9da16f 22             [ "HTTP",  "http://127.0.0.1:8081/cas.php", null, null, "Authenticated as user123", "Authenticated as user123" ] as Object[],
JK 23             [ "HTTP GET", "http://127.0.0.1:8081/cas.php", null, "GET", "Authenticated as user123", "Authenticated as user123" ] as Object[],
24             [ "HTTP POST", "http://127.0.0.1:8081/cas.php", null, "POST", "Authenticated as user123", "Authenticated as user123" ] as Object[],
5686c9 25             
JK 26             // HTTPS should succeed
9da16f 27             [ "HTTPS", "https://127.0.0.1:8444/cas.php", "/tmp/correct.crt", null, "Authenticated as user123", "Authenticated as user123" ] as Object[],
JK 28             [ "HTTPS GET", "https://127.0.0.1:8444/cas.php", "/tmp/correct.crt", "GET", "Authenticated as user123", "Authenticated as user123" ] as Object[],
29             [ "HTTPS POST", "https://127.0.0.1:8444/cas.php", "/tmp/correct.crt", "POST", "Authenticated as user123", "Authenticated as user123" ] as Object[],
5686c9 30             
JK 31             // system CAfile does not contain this self-signed certificate - should fail
9da16f 32             [ "HTTPS SysCA", "https://127.0.0.1:8444/cas.php", null, null, "CAS server is unavailable", "Not authenticated." ] as Object[],
JK 33             [ "HTTPS SysCA GET", "https://127.0.0.1:8444/cas.php", null, "GET", "CAS server is unavailable", "Not authenticated." ] as Object[],
34             [ "HTTPS SysCA POST", "https://127.0.0.1:8444/cas.php", null, "POST", "CAS server is unavailable", "Not authenticated." ] as Object[],
5686c9 35             // wrongcn.crt does not contain correct.crt - should fail
9da16f 36             [ "HTTPS WrongCA", "https://127.0.0.1:8444/cas.php", "/tmp/wrongcn.crt", null, "CAS server is unavailable", "Not authenticated." ] as Object[],
JK 37             [ "HTTPS WrongCA GET", "https://127.0.0.1:8444/cas.php", "/tmp/wrongcn.crt", "GET", "CAS server is unavailable", "Not authenticated." ] as Object[],
38             [ "HTTPS WrongCA POST", "https://127.0.0.1:8444/cas.php", "/tmp/wrongcn.crt", "POST", "CAS server is unavailable", "Not authenticated." ] as Object[],
5686c9 39             
JK 40             // system CAfile does not contain this self-signed certificate - should fail
9da16f 41             [ "HTTPS2 SysCA", "https://127.0.0.1:8445/cas.php", null, null, "CAS server is unavailable", "Not authenticated." ] as Object[],
JK 42             [ "HTTPS2 SysCA GET", "https://127.0.0.1:8445/cas.php", null, "GET", "CAS server is unavailable", "Not authenticated." ] as Object[],
43             [ "HTTPS2 SysCA POST", "https://127.0.0.1:8445/cas.php", null, "POST", "CAS server is unavailable", "Not authenticated." ] as Object[],
5686c9 44             // correct.crt does not contain wrongcn.crt - should fail
9da16f 45             [ "HTTPS2 WrongCA", "https://127.0.0.1:8445/cas.php", "/tmp/correct.crt", null, "CAS server is unavailable", "Not authenticated." ] as Object[],
JK 46             [ "HTTPS2 WrongCA GET", "https://127.0.0.1:8445/cas.php", "/tmp/correct.crt", "GET", "CAS server is unavailable", "Not authenticated." ] as Object[],
47             [ "HTTPS2 WrongCA POST", "https://127.0.0.1:8445/cas.php", "/tmp/correct.crt", "POST", "CAS server is unavailable", "Not authenticated." ] as Object[],
5686c9 48             // wrongcn.crt is issued to 127.0.0.2, not 127.0.0.1 - should fail
9da16f 49             [ "HTTPS2 CN", "https://127.0.0.1:8445/cas.php", "/tmp/wrongcn.crt", null, "CAS server is unavailable", "Not authenticated." ] as Object[],
JK 50             [ "HTTPS2 CN GET", "https://127.0.0.1:8445/cas.php", "/tmp/wrongcn.crt", "GET", "CAS server is unavailable", "Not authenticated." ] as Object[],
51             [ "HTTPS2 CN POST", "https://127.0.0.1:8445/cas.php", "/tmp/wrongcn.crt", "POST", "CAS server is unavailable", "Not authenticated." ] as Object[],
5686c9 52         ]
JK 53     }
54     
55     @Parameter(0)
9da16f 56     public String name
5686c9 57     @Parameter(1)
9da16f 58     public String cas
5686c9 59     @Parameter(2)
9da16f 60     public String cafile
5686c9 61     @Parameter(3)
9da16f 62     public String method
5686c9 63     @Parameter(4)
9da16f 64     public String expectLogin
JK 65     @Parameter(5)
5686c9 66     public String expectMain
JK 67     
68     @Test
69     public void testSinglePage() {
70         WebDriver driver = Common.set(cas, cafile, method)
71         
72         def url = Config.baseUrl + "/basic/"
73         Common.loginSingle(url, driver)
74         
75         if(method.equals("GET")) {
76             assert driver.getCurrentUrl().contains("ticket=")
77         } else {
78             assert !driver.getCurrentUrl().contains("ticket=")
79         }
80         
81         // Post-login
82         assert driver.getPageSource().contains(expectLogin)
83     }
84     
85     @Test
86     public void testMultiPage() {
87         WebDriver driver = Common.set(cas, cafile, method)
88         
89         def url = Config.baseUrl + "/login-page/"
90         Common.loginMulti(url, driver)
91         
92         // Post-login
93         assert driver.getPageSource().contains(expectLogin)
94         
95         // Main page (again)
96         driver.get(url)
97         assert driver.getPageSource().contains(expectMain)
98     }
99 }