blob: b6c9fe8175fdc5eed37fe79152271bc1d58e6f5c [file] [log] [blame]
Ray Milkey967776a2015-10-07 14:37:17 -07001/*
Brian O'Connor4e33be22017-08-03 22:45:46 -07002 * Copyright 2015-present Open Networking Foundation
Ray Milkey967776a2015-10-07 14:37:17 -07003 *
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 Scandolocf847b82019-04-26 15:00:00 -070016package org.opencord.aaa.impl;
Ray Milkey967776a2015-10-07 14:37:17 -070017
18import org.junit.Before;
19import org.junit.Ignore;
20import org.junit.Test;
21import org.onlab.packet.EAP;
22import org.onlab.packet.EAPOL;
23import org.onlab.packet.Ethernet;
24import org.onosproject.core.CoreServiceAdapter;
25import org.onosproject.net.config.Config;
26import org.onosproject.net.config.NetworkConfigRegistryAdapter;
Matteo Scandolocf847b82019-04-26 15:00:00 -070027import org.opencord.aaa.AaaConfig;
kartikey dubeye1545422019-05-22 12:53:45 +000028import org.opencord.aaa.impl.AaaTestBase.MockCfgService;
Ray Milkey967776a2015-10-07 14:37:17 -070029
30import static org.hamcrest.Matchers.is;
31import static org.hamcrest.Matchers.notNullValue;
32import static org.junit.Assert.assertThat;
33
34/**
35 * Set of tests of the ONOS application component. These use an existing RADIUS
36 * server and sends live packets over the network to it.
37 */
38@Ignore ("This should not be run as part of the standard build")
Jonathan Hart092dfb22015-11-16 23:05:21 -080039public class AaaIntegrationTest extends AaaTestBase {
Ray Milkey967776a2015-10-07 14:37:17 -070040
Jonathan Hart092dfb22015-11-16 23:05:21 -080041 private AaaManager aaa;
Ray Milkey967776a2015-10-07 14:37:17 -070042
43 /**
44 * Mocks the network config registry.
45 */
46 @SuppressWarnings("unchecked")
47 static final class TestNetworkConfigRegistry
48 extends NetworkConfigRegistryAdapter {
49 @Override
50 public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
Jonathan Hart092dfb22015-11-16 23:05:21 -080051 return (C) new AaaConfig();
Ray Milkey967776a2015-10-07 14:37:17 -070052 }
53 }
54
55 /**
56 * Sets up the services required by the AAA application.
57 */
58 @Before
59 public void setUp() {
Jonathan Hart092dfb22015-11-16 23:05:21 -080060 aaa = new AaaManager();
Ray Milkey967776a2015-10-07 14:37:17 -070061 aaa.netCfgService = new TestNetworkConfigRegistry();
62 aaa.coreService = new CoreServiceAdapter();
63 aaa.packetService = new MockPacketService();
kartikey dubeye1545422019-05-22 12:53:45 +000064 aaa.cfgService = new MockCfgService();
65 aaa.activate(new AaaTestBase.MockComponentContext());
Ray Milkey967776a2015-10-07 14:37:17 -070066 }
67
68 /**
69 * Fetches the sent packet at the given index. The requested packet
70 * must be the last packet on the list.
71 *
72 * @param index index into sent packets array
73 * @return packet
74 */
75 private Ethernet fetchPacket(int index) {
76 for (int iteration = 0; iteration < 20; iteration++) {
77 if (savedPackets.size() > index) {
78 return (Ethernet) savedPackets.get(index);
79 } else {
80 try {
81 Thread.sleep(250);
82 } catch (Exception ex) {
83 return null;
84 }
85 }
86 }
87 return null;
88 }
89
90 /**
91 * Tests the authentication path through the AAA application by sending
92 * packets to the RADIUS server and checking the state machine
93 * transitions.
94 *
95 * @throws Exception when an unhandled error occurs
96 */
97 @Test
98 public void testAuthentication() throws Exception {
99
100 // (1) Supplicant start up
101
102 Ethernet startPacket = constructSupplicantStartPacket();
103 sendPacket(startPacket);
104
105 Ethernet responsePacket = fetchPacket(0);
106 assertThat(responsePacket, notNullValue());
107 checkRadiusPacket(aaa, responsePacket, EAP.REQUEST);
108
109 // (2) Supplicant identify
110
111 Ethernet identifyPacket = constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null);
112 sendPacket(identifyPacket);
113
114 // State machine should have been created by now
115
Jonathan Hart612651f2019-11-25 09:21:43 -0800116 StateMachine stateMachine = aaa.getStateMachine(SESSION_ID);
Ray Milkey967776a2015-10-07 14:37:17 -0700117 assertThat(stateMachine, notNullValue());
118 assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING));
119
120 // (3) RADIUS MD5 challenge
121
122 Ethernet radiusChallengeMD5Packet = fetchPacket(1);
123 assertThat(radiusChallengeMD5Packet, notNullValue());
124 checkRadiusPacket(aaa, radiusChallengeMD5Packet, EAP.REQUEST);
125
126
127 // (4) Supplicant MD5 response
128
129 Ethernet md5RadiusPacket =
130 constructSupplicantIdentifyPacket(stateMachine,
131 EAP.ATTR_MD5,
132 stateMachine.challengeIdentifier(),
133 radiusChallengeMD5Packet);
134 sendPacket(md5RadiusPacket);
135
136
137 // (5) RADIUS Success
138
139 Ethernet successRadiusPacket = fetchPacket(2);
140 assertThat(successRadiusPacket, notNullValue());
Jonathan Hart092dfb22015-11-16 23:05:21 -0800141 EAPOL successEapol = (EAPOL) successRadiusPacket.getPayload();
142 EAP successEap = (EAP) successEapol.getPayload();
143 assertThat(successEap.getCode(), is(EAP.SUCCESS));
Ray Milkey967776a2015-10-07 14:37:17 -0700144
145 // State machine should be in authorized state
146
147 assertThat(stateMachine, notNullValue());
148 assertThat(stateMachine.state(), is(StateMachine.STATE_AUTHORIZED));
149
150 }
151
152}
153