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