Skip to content

Commit

Permalink
NMS-15802 Ensure that user-info attribute can provide basic authentic…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
dherdt committed Jul 6, 2023
1 parent 7a335b3 commit 690ac46
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;

import java.net.InetAddress;
Expand All @@ -43,7 +42,6 @@

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opennms.core.test.MockLogAppender;
Expand Down Expand Up @@ -378,4 +376,30 @@ public void testHeaders() throws Exception {
assertEquals(PollStatus.SERVICE_UNAVAILABLE, status2.getStatusCode());
assertNotNull(status2.getReason());
}

@Test
@JUnitHttpServer(basicAuth = true, port = 10342, webapps = @Webapp(context = "/opennms", path = "src/test/resources/loginTestWar"))
public void testUserInfoToBasicAuth() throws Exception {
final Map<String, Object> params1 = new HashMap<>(m_params);
String correctUserInfo = "admin:istrator";
params1.put("page-sequence", "" +
"<?xml version=\"1.0\"?>" +
"<page-sequence>\n" +
" <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" port=\"10342\" method=\"POST\" response-range=\"300-399\" locationMatch=\"/opennms/\" user-info=\"" + correctUserInfo + "\" />\n" +
"</page-sequence>\n");
final PollStatus status1 = m_monitor.poll(getHttpService("localhost"), params1);
assertEquals(PollStatus.SERVICE_AVAILABLE, status1.getStatusCode());
assertNull(status1.getReason());

final Map<String, Object> params2 = new HashMap<>(m_params);
String wrongUserInfo = "admin:wrong";
params2.put("page-sequence", "" +
"<?xml version=\"1.0\"?>" +
"<page-sequence>\n" +
" <page virtual-host=\"localhost\" path=\"/opennms/j_spring_security_check\" port=\"10342\" method=\"POST\" response-range=\"300-399\" locationMatch=\"/opennms/\" user-info=\"" + wrongUserInfo + "\" />\n" +
"</page-sequence>\n");
final PollStatus status2 = m_monitor.poll(getHttpService("localhost"), params2);
assertEquals(PollStatus.SERVICE_UNAVAILABLE, status2.getStatusCode());
assertNotNull(status2.getReason());
}
}

0 comments on commit 690ac46

Please sign in to comment.