Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 4e33be2 | 2017-08-03 22:45:46 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 16 | package org.opencord.aaa.impl; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 17 | |
| 18 | import org.junit.After; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
Matteo Scandolo | bbc1ffb | 2020-10-16 15:56:20 -0700 | [diff] [blame^] | 21 | import org.junit.runner.RunWith; |
| 22 | import org.junit.runners.Parameterized; |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 23 | import org.onlab.junit.TestUtils; |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 24 | import org.onlab.packet.BasePacket; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 25 | import org.onlab.packet.DeserializationException; |
| 26 | import org.onlab.packet.EAP; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 27 | import org.onlab.packet.Ethernet; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 28 | import org.onlab.packet.IpAddress; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 29 | import org.onlab.packet.RADIUS; |
| 30 | import org.onlab.packet.RADIUSAttribute; |
Jonathan Hart | c41227c | 2020-01-28 16:56:49 -0800 | [diff] [blame] | 31 | import org.onosproject.cluster.ClusterServiceAdapter; |
| 32 | import org.onosproject.cluster.LeadershipServiceAdapter; |
| 33 | import org.onosproject.cluster.NodeId; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 34 | import org.onosproject.core.CoreServiceAdapter; |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 35 | import org.onosproject.event.DefaultEventSinkRegistry; |
| 36 | import org.onosproject.event.Event; |
| 37 | import org.onosproject.event.EventDeliveryService; |
| 38 | import org.onosproject.event.EventSink; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 39 | import org.onosproject.net.config.Config; |
| 40 | import org.onosproject.net.config.NetworkConfigRegistryAdapter; |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 41 | import org.onosproject.net.packet.InboundPacket; |
Jonathan Hart | c41227c | 2020-01-28 16:56:49 -0800 | [diff] [blame] | 42 | import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter; |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 43 | import org.onosproject.store.service.TestStorageService; |
Matteo Scandolo | cf847b8 | 2019-04-26 15:00:00 -0700 | [diff] [blame] | 44 | import org.opencord.aaa.AaaConfig; |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 45 | import org.slf4j.Logger; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 46 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 47 | import java.net.InetAddress; |
| 48 | import java.net.UnknownHostException; |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 49 | import java.util.concurrent.atomic.AtomicReference; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 50 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 51 | import static com.google.common.base.Preconditions.checkState; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 52 | import static org.hamcrest.Matchers.is; |
| 53 | import static org.hamcrest.Matchers.notNullValue; |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 54 | import static org.hamcrest.Matchers.nullValue; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 55 | import static org.junit.Assert.assertThat; |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 56 | import static org.junit.Assert.fail; |
| 57 | import static org.onosproject.net.intent.TestTools.assertAfter; |
| 58 | import static org.slf4j.LoggerFactory.getLogger; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * Set of tests of the ONOS application component. |
| 62 | */ |
Matteo Scandolo | bbc1ffb | 2020-10-16 15:56:20 -0700 | [diff] [blame^] | 63 | @RunWith(Parameterized.class) |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 64 | public class AaaManagerTest extends AaaTestBase { |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 65 | |
Matteo Scandolo | bbc1ffb | 2020-10-16 15:56:20 -0700 | [diff] [blame^] | 66 | // Change this to have more run with mvn |
| 67 | @Parameterized.Parameters |
| 68 | public static Object[][] data() { |
| 69 | return new Object[1][0]; |
| 70 | } |
| 71 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 72 | static final String BAD_IP_ADDRESS = "198.51.100.0"; |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 73 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 74 | private final Logger log = getLogger(getClass()); |
| 75 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 76 | private AaaManager aaaManager; |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 77 | private AaaStatisticsManager aaaStatisticsManager; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 78 | |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 79 | class AaaManagerWithoutRadiusServer extends AaaManager { |
Amit Ghosh | c9ac1e5 | 2017-07-28 12:31:18 +0100 | [diff] [blame] | 80 | protected void sendRadiusPacket(RADIUS radiusPacket, InboundPacket inPkt) { |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 81 | savePacket(radiusPacket); |
| 82 | } |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 83 | } |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 84 | /** |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 85 | * Mocks the AAAConfig class to force usage of an unroutable address for the |
| 86 | * RADIUS server. |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 87 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 88 | static class MockAaaConfig extends AaaConfig { |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 89 | @Override |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 90 | public InetAddress radiusIp() { |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 91 | try { |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 92 | return InetAddress.getByName(BAD_IP_ADDRESS); |
| 93 | } catch (UnknownHostException ex) { |
| 94 | // can't happen |
| 95 | throw new IllegalStateException(ex); |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
Jonathan Hart | c41227c | 2020-01-28 16:56:49 -0800 | [diff] [blame] | 100 | static final class TestLeadershipService extends LeadershipServiceAdapter { |
| 101 | @Override |
| 102 | public NodeId getLeader(String path) { |
| 103 | return new ClusterServiceAdapter().getLocalNode().id(); |
| 104 | } |
| 105 | } |
| 106 | |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 107 | /** |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 108 | * Mocks the network config registry. |
| 109 | */ |
| 110 | @SuppressWarnings("unchecked") |
| 111 | private static final class TestNetworkConfigRegistry |
| 112 | extends NetworkConfigRegistryAdapter { |
| 113 | @Override |
| 114 | public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 115 | AaaConfig aaaConfig = new MockAaaConfig(); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 116 | return (C) aaaConfig; |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 120 | public static class TestEventDispatcher extends DefaultEventSinkRegistry |
| 121 | implements EventDeliveryService { |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 122 | @Override |
| 123 | @SuppressWarnings("unchecked") |
| 124 | public synchronized void post(Event event) { |
| 125 | EventSink sink = getSink(event.getClass()); |
| 126 | checkState(sink != null, "No sink for event %s", event); |
| 127 | sink.process(event); |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public void setDispatchTimeLimit(long millis) { |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public long getDispatchTimeLimit() { |
| 136 | return 0; |
| 137 | } |
| 138 | } |
| 139 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 140 | /** |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 141 | * Sets up the services required by the AAA application. |
| 142 | */ |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 143 | @Before |
| 144 | public void setUp() { |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 145 | aaaManager = new AaaManagerWithoutRadiusServer(); |
| 146 | aaaManager.netCfgService = new TestNetworkConfigRegistry(); |
| 147 | aaaManager.coreService = new CoreServiceAdapter(); |
| 148 | aaaManager.packetService = new MockPacketService(); |
Amit Ghosh | f739be5 | 2017-09-21 15:49:37 +0100 | [diff] [blame] | 149 | aaaManager.deviceService = new TestDeviceService(); |
Gamze Abaka | 1cfdb19 | 2018-10-25 11:39:19 +0000 | [diff] [blame] | 150 | aaaManager.sadisService = new MockSadisService(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 151 | aaaManager.cfgService = new MockCfgService(); |
Jonathan Hart | 9d1ce80 | 2020-01-28 10:45:08 -0800 | [diff] [blame] | 152 | aaaManager.storageService = new TestStorageService(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 153 | aaaStatisticsManager = new AaaStatisticsManager(); |
Jonathan Hart | c41227c | 2020-01-28 16:56:49 -0800 | [diff] [blame] | 154 | aaaStatisticsManager.storageService = new TestStorageService(); |
| 155 | aaaStatisticsManager.clusterService = new ClusterServiceAdapter(); |
| 156 | aaaStatisticsManager.leadershipService = new TestLeadershipService(); |
| 157 | aaaStatisticsManager.clusterCommunicationService = new ClusterCommunicationServiceAdapter(); |
Shubham Sharma | 4900ce6 | 2019-06-19 14:18:50 +0000 | [diff] [blame] | 158 | aaaManager.radiusOperationalStatusService = new RadiusOperationalStatusManager(); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 159 | TestUtils.setField(aaaStatisticsManager, "eventDispatcher", new TestEventDispatcher()); |
Jonathan Hart | c41227c | 2020-01-28 16:56:49 -0800 | [diff] [blame] | 160 | aaaStatisticsManager.activate(new MockComponentContext()); |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 161 | aaaManager.aaaStatisticsManager = this.aaaStatisticsManager; |
Jonathan Hart | 5db4453 | 2018-07-12 18:13:54 -0700 | [diff] [blame] | 162 | TestUtils.setField(aaaManager, "eventDispatcher", new TestEventDispatcher()); |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 163 | |
| 164 | |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 165 | aaaManager.activate(new AaaTestBase.MockComponentContext()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 168 | /** |
| 169 | * Tears down the AAA application. |
| 170 | */ |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 171 | @After |
| 172 | public void tearDown() { |
kartikey dubey | e154542 | 2019-05-22 12:53:45 +0000 | [diff] [blame] | 173 | aaaManager.deactivate(new AaaTestBase.MockComponentContext()); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 176 | /** |
| 177 | * Extracts the RADIUS packet from a packet sent by the supplicant. |
| 178 | * |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 179 | * @param radius RADIUS packet sent by the supplicant |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 180 | * @throws DeserializationException if deserialization of the packet contents |
| 181 | * fails. |
| 182 | */ |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 183 | private void checkRadiusPacketFromSupplicant(RADIUS radius) |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 184 | throws DeserializationException { |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 185 | assertThat(radius, notNullValue()); |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 186 | |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 187 | EAP eap = radius.decapsulateMessage(); |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 188 | assertThat(eap, notNullValue()); |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Fetches the sent packet at the given index. The requested packet |
| 193 | * must be the last packet on the list. |
| 194 | * |
| 195 | * @param index index into sent packets array |
| 196 | * @return packet |
| 197 | */ |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 198 | private BasePacket fetchPacket(int index) { |
| 199 | BasePacket packet = savedPackets.get(index); |
| 200 | assertThat(packet, notNullValue()); |
| 201 | return packet; |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /** |
| 205 | * Tests the authentication path through the AAA application. |
| 206 | * |
| 207 | * @throws DeserializationException if packed deserialization fails. |
| 208 | */ |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 209 | @Test |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 210 | public void testAuthentication() throws Exception { |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 211 | |
| 212 | // (1) Supplicant start up |
| 213 | |
| 214 | Ethernet startPacket = constructSupplicantStartPacket(); |
| 215 | sendPacket(startPacket); |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 216 | assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> { |
Andrea Campanella | c4781e6 | 2020-10-08 12:58:45 +0200 | [diff] [blame] | 217 | Ethernet responsePacket = (Ethernet) fetchPacket(0); |
| 218 | checkRadiusPacket(aaaManager, responsePacket, EAP.ATTR_IDENTITY); |
| 219 | |
| 220 | // (2) Supplicant identify |
| 221 | |
| 222 | Ethernet identifyPacket = null; |
| 223 | try { |
| 224 | identifyPacket = constructSupplicantIdentifyPacket(null, |
| 225 | EAP.ATTR_IDENTITY, (byte) 3, null); |
| 226 | } catch (Exception e) { |
| 227 | log.error(e.getMessage()); |
| 228 | fail(); |
| 229 | } |
| 230 | sendPacket(identifyPacket); |
| 231 | }); |
| 232 | assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> { |
| 233 | RADIUS radiusIdentifyPacket = (RADIUS) fetchPacket(1); |
| 234 | AtomicReference<Byte> reqId = new AtomicReference<>(radiusIdentifyPacket.getIdentifier()); |
| 235 | |
| 236 | try { |
| 237 | checkRadiusPacketFromSupplicant(radiusIdentifyPacket); |
| 238 | } catch (DeserializationException e) { |
| 239 | log.error(e.getMessage()); |
| 240 | fail(); |
| 241 | } |
| 242 | |
| 243 | assertThat(radiusIdentifyPacket.getCode(), is(RADIUS.RADIUS_CODE_ACCESS_REQUEST)); |
| 244 | assertThat(new String(radiusIdentifyPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME).getValue()), |
| 245 | is("testuser")); |
| 246 | |
| 247 | IpAddress nasIp = |
| 248 | IpAddress.valueOf(IpAddress.Version.INET, |
| 249 | radiusIdentifyPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP) |
| 250 | .getValue()); |
| 251 | assertThat(nasIp.toString(), is(aaaManager.nasIpAddress.getHostAddress())); |
| 252 | |
| 253 | // (3) RADIUS MD5 challenge |
| 254 | |
| 255 | RADIUS radiusCodeAccessChallengePacket = |
| 256 | constructRadiusCodeAccessChallengePacket(RADIUS.RADIUS_CODE_ACCESS_CHALLENGE, EAP.ATTR_MD5, |
| 257 | reqId.get(), aaaManager.radiusSecret.getBytes()); |
| 258 | aaaManager.handleRadiusPacket(radiusCodeAccessChallengePacket); |
| 259 | }); |
| 260 | assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> { |
| 261 | |
| 262 | // State machine should have been created by now |
| 263 | |
| 264 | StateMachine stateMachine = aaaManager.getStateMachine(SESSION_ID); |
| 265 | assertThat(stateMachine, notNullValue()); |
| 266 | assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING)); |
| 267 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 268 | Ethernet radiusChallengeMD5Packet = (Ethernet) fetchPacket(2); |
| 269 | checkRadiusPacket(aaaManager, radiusChallengeMD5Packet, EAP.ATTR_MD5); |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 270 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 271 | // (4) Supplicant MD5 response |
| 272 | try { |
| 273 | Ethernet md5RadiusPacket = |
| 274 | constructSupplicantIdentifyPacket(stateMachine, |
| 275 | EAP.ATTR_MD5, |
| 276 | stateMachine.challengeIdentifier(), |
| 277 | radiusChallengeMD5Packet); |
| 278 | sendPacket(md5RadiusPacket); |
| 279 | } catch (Exception e) { |
| 280 | log.error(e.getMessage()); |
| 281 | fail(); |
| 282 | } |
| 283 | }); |
Andrea Campanella | c4781e6 | 2020-10-08 12:58:45 +0200 | [diff] [blame] | 284 | |
| 285 | // State machine should have been created by now |
| 286 | |
| 287 | StateMachine stateMachine = aaaManager.getStateMachine(SESSION_ID); |
| 288 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 289 | assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> { |
Andrea Campanella | c4781e6 | 2020-10-08 12:58:45 +0200 | [diff] [blame] | 290 | |
| 291 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 292 | RADIUS responseMd5RadiusPacket = (RADIUS) fetchPacket(3); |
| 293 | try { |
| 294 | checkRadiusPacketFromSupplicant(responseMd5RadiusPacket); |
| 295 | } catch (Exception e) { |
| 296 | log.error(e.getMessage()); |
| 297 | fail(); |
| 298 | } |
| 299 | //assertThat(responseMd5RadiusPacket.getIdentifier(), is((byte) 9)); |
Andrea Campanella | c4781e6 | 2020-10-08 12:58:45 +0200 | [diff] [blame] | 300 | AtomicReference<Byte> reqId = new AtomicReference<>(responseMd5RadiusPacket.getIdentifier()); |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 301 | assertThat(responseMd5RadiusPacket.getCode(), is(RADIUS.RADIUS_CODE_ACCESS_REQUEST)); |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 302 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 303 | // State machine should be in pending state |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 304 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 305 | assertThat(stateMachine, notNullValue()); |
| 306 | assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING)); |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 307 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 308 | // (5) RADIUS Success |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 309 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 310 | RADIUS successPacket = |
| 311 | constructRadiusCodeAccessChallengePacket(RADIUS.RADIUS_CODE_ACCESS_ACCEPT, |
| 312 | EAP.SUCCESS, reqId.get(), |
| 313 | aaaManager.radiusSecret.getBytes()); |
| 314 | aaaManager.handleRadiusPacket((successPacket)); |
| 315 | }); |
| 316 | assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> { |
| 317 | Ethernet supplicantSuccessPacket = (Ethernet) fetchPacket(4); |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 318 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 319 | checkRadiusPacket(aaaManager, supplicantSuccessPacket, EAP.SUCCESS); |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 320 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 321 | // State machine should be in authorized state |
Ray Milkey | ea36645 | 2015-09-30 10:56:43 -0700 | [diff] [blame] | 322 | |
Matteo Scandolo | 9510e5d | 2020-09-24 17:31:52 -0700 | [diff] [blame] | 323 | assertThat(stateMachine, notNullValue()); |
| 324 | assertThat(stateMachine.state(), is(StateMachine.STATE_AUTHORIZED)); |
| 325 | }); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 326 | } |
Ray Milkey | 967776a | 2015-10-07 14:37:17 -0700 | [diff] [blame] | 327 | |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 328 | @Test |
| 329 | public void testRemoveAuthentication() { |
| 330 | Ethernet startPacket = constructSupplicantStartPacket(); |
| 331 | sendPacket(startPacket); |
Andrea Campanella | c4781e6 | 2020-10-08 12:58:45 +0200 | [diff] [blame] | 332 | assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> { |
| 333 | StateMachine stateMachine = aaaManager.getStateMachine(SESSION_ID); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 334 | |
Andrea Campanella | c4781e6 | 2020-10-08 12:58:45 +0200 | [diff] [blame] | 335 | assertThat(stateMachine, notNullValue()); |
| 336 | assertThat(stateMachine.state(), is(StateMachine.STATE_STARTED)); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 337 | |
Andrea Campanella | c4781e6 | 2020-10-08 12:58:45 +0200 | [diff] [blame] | 338 | aaaManager.removeAuthenticationStateByMac(stateMachine.supplicantAddress()); |
Jonathan Hart | 612651f | 2019-11-25 09:21:43 -0800 | [diff] [blame] | 339 | |
Andrea Campanella | c4781e6 | 2020-10-08 12:58:45 +0200 | [diff] [blame] | 340 | assertThat(aaaManager.getStateMachine(SESSION_ID), nullValue()); |
| 341 | }); |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 342 | } |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 343 | |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 344 | /** |
| 345 | * Tests the default configuration. |
| 346 | */ |
| 347 | @Test |
| 348 | public void testConfig() { |
Jonathan Hart | 092dfb2 | 2015-11-16 23:05:21 -0800 | [diff] [blame] | 349 | assertThat(aaaManager.nasIpAddress.getHostAddress(), is(AaaConfig.DEFAULT_NAS_IP)); |
| 350 | assertThat(aaaManager.nasMacAddress, is(AaaConfig.DEFAULT_NAS_MAC)); |
| 351 | assertThat(aaaManager.radiusIpAddress.getHostAddress(), is(BAD_IP_ADDRESS)); |
| 352 | assertThat(aaaManager.radiusMacAddress, is(AaaConfig.DEFAULT_RADIUS_MAC)); |
Ray Milkey | fcb623d | 2015-10-01 16:48:18 -0700 | [diff] [blame] | 353 | } |
Ari Saha | 8983174 | 2015-06-26 10:31:48 -0700 | [diff] [blame] | 354 | } |