use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class SSLCertMonitorIT method testExpiredDateForCertificate.
@Test
@JUnitHttpServer(port = 10342, https = true)
public void testExpiredDateForCertificate() throws UnknownHostException {
SSLCertMonitor monitor = new SSLCertMonitor() {
@Override
protected Calendar getCalendarInstance() {
final Calendar cal = GregorianCalendar.getInstance();
cal.setTimeInMillis(EXPIRE_DATE - 86400000 * -1);
return cal;
}
};
Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
parameters.put("port", "10342");
parameters.put("retry", "0");
parameters.put("timeout", "500");
parameters.put("verbose", "true");
parameters.put("days", "5");
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "SSLCert");
PollStatus status = monitor.poll(svc, parameters);
assertTrue(status.isUnavailable());
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class SSLCertMonitorIT method testHostNameVerificationFails.
@Test
@JUnitHttpServer(port = 10342, https = true)
public void testHostNameVerificationFails() throws UnknownHostException {
SSLCertMonitor monitor = new SSLCertMonitor() {
@Override
protected Calendar getCalendarInstance() {
final Calendar cal = GregorianCalendar.getInstance();
cal.setTimeInMillis(EXPIRE_DATE - 86400000 * 5);
return cal;
}
};
Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
parameters.put("port", "10342");
parameters.put("retry", "0");
parameters.put("timeout", "500");
parameters.put("verbose", "true");
parameters.put("days", "5");
parameters.put("server-name", "klatschmohnwiese");
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "SSLCert");
PollStatus status = monitor.poll(svc, parameters);
assertTrue(status.isUnavailable());
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class HttpMonitorIT method testNMS2702.
@Test
@JUnitHttpServer()
public void testNMS2702() throws UnknownHostException {
HttpMonitor monitor = new HttpMonitor();
Map<String, Object> parameters = new ConcurrentSkipListMap<String, Object>();
final int port = JUnitHttpServerExecutionListener.getPort();
if (port > 0) {
parameters.put("port", String.valueOf(port));
} else {
throw new IllegalStateException("Unable to determine what port the HTTP server started on!");
}
parameters.put("url", "/test-NMS2702.html");
parameters.put("retry", "1");
parameters.put("timeout", "500");
parameters.put("verbose", "true");
// Match a string included on Initial Server Response
parameters.put("response-text", "~.*OK.*");
MonitoredService svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "HTTP");
PollStatus status = monitor.poll(svc, parameters);
assertTrue(status.isAvailable());
// Match a string included on Header
parameters.put("response-text", "~.*Jetty.*");
svc = MonitorTestUtils.getMonitoredService(3, "localhost", DnsUtils.resolveHostname("localhost", false), "HTTP");
status = monitor.poll(svc, parameters);
assertTrue(status.isAvailable());
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testLoginDynamicCredentials.
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testLoginDynamicCredentials() 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\">\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");
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));
}
use of org.opennms.core.test.http.annotations.JUnitHttpServer in project opennms by OpenNMS.
the class PageSequenceMonitorIT method testRedirectLocationMatch.
@Test
@JUnitHttpServer(port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testRedirectLocationMatch() 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=\"/opennms/\">\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 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