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