use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class SimpleBackEndTest method testBackendWithBasicAuth.
@Test
@JUnitHttpServer(port = 9162, basicAuth = true, webapps = @Webapp(context = "/", path = "src/test/resources/simple-test-webapp"))
public void testBackendWithBasicAuth() throws Exception {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("testuser", "testpassword"));
assertNotNull(m_authBackEnd);
assertEquals("first get should be 0", 0, m_authBackEnd.getCount());
assertEquals("second should be 1", 1, m_authBackEnd.getCount());
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class TcpMonitorIT method testLocalhostConnection.
@Test
@JUnitHttpServer(port = 10342)
public void testLocalhostConnection() throws UnknownHostException {
Map<String, Object> m = new ConcurrentSkipListMap<String, Object>();
Parameter p = new Parameter();
ServiceMonitor monitor = new TcpMonitor();
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost"), "TCP");
p.setKey("port");
p.setValue("10342");
m.put(p.getKey(), p.getValue());
p.setKey("retry");
p.setValue("1");
m.put(p.getKey(), p.getValue());
p.setKey("timeout");
p.setValue("500");
m.put(p.getKey(), p.getValue());
PollStatus status = monitor.poll(svc, m);
MockUtil.println("Reason: " + status.getReason());
assertEquals(PollStatus.SERVICE_AVAILABLE, status.getStatusCode());
assertNull(status.getReason());
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testLoginDynamicCredentialsTwice.
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testLoginDynamicCredentialsTwice() throws Exception {
m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + " <page path=\"/opennms/\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"(?s)>Login (.)(.)(.)(.) Username and Password<\">\n" + " <session-variable name=\"ltr1\" match-group=\"1\" />\n" + " <session-variable name=\"ltr2\" match-group=\"2\" />\n" + " <session-variable name=\"ltr3\" match-group=\"3\" />\n" + " <session-variable name=\"ltr4\" match-group=\"4\" />\n" + " </page>\n" + " <!-- Pick out the letters w-i-t-h to try and log in, this will fail -->\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" response-range=\"300-399\" locationMatch=\"/opennms/spring_security_login\\?login_error\" port=\"10342\" method=\"POST\">\n" + " <parameter key=\"j_username\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " <parameter key=\"j_password\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/spring_security_login\" query=\"login_error\" port=\"10342\" failureMatch=\"(?s)Log out\" failureMessage=\"Login should have failed but did not\" successMatch=\"Your login attempt was not successful\"/>\n" + " <!-- Pick out the letters d-e-m-o to try and log in, this will succeed -->\n" + " <page path=\"/opennms/\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"(?s)<hea(.)><titl(.)>.*</for(.)></b(.)dy>\">\n" + " <session-variable name=\"ltr1\" match-group=\"1\" />\n" + " <session-variable name=\"ltr2\" match-group=\"2\" />\n" + " <session-variable name=\"ltr3\" match-group=\"3\" />\n" + " <session-variable name=\"ltr4\" match-group=\"4\" />\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" response-range=\"300-399\" port=\"10342\" method=\"POST\">\n" + " <parameter key=\"j_username\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " <parameter key=\"j_password\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/events.html\" port=\"10342\" successMatch=\"Event Queries\" />\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_logout\" port=\"10342\" successMatch=\"Login with Username and Password\" />\n" + "</page-sequence>\n");
try {
PollStatus status = m_monitor.poll(getHttpService("localhost"), m_params);
assertTrue("Expected available but was " + status + ": reason = " + status.getReason(), status.isAvailable());
assertTrue("Expected a DS called 'response-time' but did not find one", status.getProperties().containsKey(PollStatus.PROPERTY_RESPONSE_TIME));
} finally {
// Print some debug output if necessary
}
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testRedirectLocationDoesNotMatch.
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testRedirectLocationDoesNotMatch() throws Exception {
m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + " <page path=\"/opennms/\" port=\"10342\" virtual-host=\"localhost\" successMatch=\"(?s)<hea(.)><titl(.)>.*</for(.)></b(.)dy>\">\n" + " <session-variable name=\"ltr1\" match-group=\"1\" />\n" + " <session-variable name=\"ltr2\" match-group=\"2\" />\n" + " <session-variable name=\"ltr3\" match-group=\"3\" />\n" + " <session-variable name=\"ltr4\" match-group=\"4\" />\n" + " </page>\n" + " <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" port=\"10342\" method=\"POST\" response-range=\"300-399\" locationMatch=\"/opensadfnms/\">\n" + " <parameter key=\"j_username\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " <parameter key=\"j_password\" value=\"${ltr1}${ltr2}${ltr3}${ltr4}\"/>\n" + " </page>\n" + "</page-sequence>\n");
PollStatus status = m_monitor.poll(getHttpService("localhost"), m_params);
assertTrue("Expected down but was " + status + ": reason = " + status.getReason(), status.isDown());
assertEquals("Failed to find '/opensadfnms/' in Location: header at http://127.0.0.1:10342/opennms/j_spring_security_check", status.getReason());
assertTrue("Expected a DS called 'response-time' but did not find one", status.getProperties().containsKey(PollStatus.PROPERTY_RESPONSE_TIME));
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testRequireIPv4.
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testRequireIPv4() throws Exception {
m_params.put("page-sequence", "" + "<?xml version=\"1.0\"?>" + "<page-sequence>\n" + " <page host=\"localhost\" virtual-host=\"localhost\" path=\"/opennms/\" port=\"10342\" requireIPv4=\"true\"/>\n" + "</page-sequence>\n");
PollStatus status = m_monitor.poll(getHttpService("localhost"), m_params);
assertTrue("Expected available but was " + status + ": reason = " + status.getReason(), status.isAvailable());
assertTrue("Expected a DS called 'response-time' but did not find one", status.getProperties().containsKey(PollStatus.PROPERTY_RESPONSE_TIME));
}
Aggregations