-
Notifications
You must be signed in to change notification settings - Fork 29
/
EndToEndTest.java
86 lines (67 loc) · 3.26 KB
/
EndToEndTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package org.tinyradius.e2e;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.tinyradius.core.RadiusPacketException;
import org.tinyradius.core.dictionary.DefaultDictionary;
import org.tinyradius.core.dictionary.Dictionary;
import org.tinyradius.core.packet.request.AccessRequest;
import org.tinyradius.core.packet.request.RadiusRequest;
import org.tinyradius.core.packet.response.RadiusResponse;
import org.tinyradius.io.server.RadiusServer;
import java.util.List;
import java.util.Map;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.tinyradius.core.packet.PacketType.*;
@Execution(ExecutionMode.SAME_THREAD)
class EndToEndTest {
private static final Dictionary dictionary = DefaultDictionary.INSTANCE;
private static final int PROXY_ACCESS_PORT = 1812;
private static final int PROXY_ACCT_PORT = 1813;
private static final String PROXY_SECRET = "myProxySecret";
private static final int ORIGIN_ACCESS_PORT = 11812;
private static final int ORIGIN_ACCT_PORT = 11813;
private static final String ORIGIN_SECRET = "myOriginSecret";
private final Harness harness = new Harness();
@Test
void testAll() throws RadiusPacketException {
var username = "user1";
var pw = "pw1";
try (var origin = startOrigin(Map.of(username, pw));
var proxy = startProxy()) {
await().until(() -> proxy.isReady().isSuccess() && origin.isReady().isSuccess());
RadiusRequest r1 = ((AccessRequest) RadiusRequest.create(dictionary, ACCESS_REQUEST, (byte) 1, null, List.of()))
.withPapPassword(pw)
.addAttribute("User-Name", username);
RadiusRequest r2 = RadiusRequest.create(dictionary, ACCOUNTING_REQUEST, (byte) 2, null, List.of())
.addAttribute("Acct-Status-Type", "1");
RadiusRequest r3 = ((AccessRequest) RadiusRequest.create(dictionary, ACCESS_REQUEST, (byte) 1, null, List.of()))
.withPapPassword("badPw")
.addAttribute("User-Name", username);
List<RadiusResponse> responses = harness.testClient("localhost", PROXY_ACCESS_PORT, PROXY_ACCT_PORT, PROXY_SECRET,
List.of(r1, r2, r3));
assertEquals(ACCESS_ACCEPT, responses.get(0).getType());
assertEquals(ACCOUNTING_RESPONSE, responses.get(1).getType());
assertEquals(ACCESS_REJECT, responses.get(2).getType());
}
}
@Test
void testProxyStartup() {
try (var proxy = startProxy()) {
await().until(() -> proxy.isReady().isSuccess());
}
}
@Test
void testOriginStartup() {
try (var origin = startOrigin(Map.of())) {
await().until(() -> origin.isReady().isSuccess());
}
}
private RadiusServer startProxy() {
return harness.startProxy(PROXY_ACCESS_PORT, PROXY_ACCT_PORT, PROXY_SECRET, ORIGIN_ACCESS_PORT, ORIGIN_ACCT_PORT, ORIGIN_SECRET);
}
private RadiusServer startOrigin(Map<String, String> credentials) {
return harness.startOrigin(ORIGIN_ACCESS_PORT, ORIGIN_ACCT_PORT, ORIGIN_SECRET, credentials);
}
}