[SEBA-897] Unit Test cases for SEBA-34
Change-Id: Ib7d691ebc02a842d81cc7c72ed153cb06dccab57
diff --git a/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java b/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java
index 3be3f4c..cdf0ede 100644
--- a/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java
+++ b/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java
@@ -333,18 +333,91 @@
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolStartReqTrans(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolTransRespNotNak(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapPktTxauthChooseEap(), ZERO);
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getValidEapolFramesRx(), ZERO);
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolFramesTx(), ZERO);
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getReqEapFramesTx(), ZERO);
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getRequestIdFramesTx(), ZERO);
+ assertEquals(aaaStatisticsManager.getAaaStats().getInvalidBodyLength(), ZERO);
+ assertEquals(aaaStatisticsManager.getAaaStats().getInvalidPktType(), ZERO);
+ assertEquals(aaaStatisticsManager.getAaaStats().getPendingResSupp(), ZERO);
+ // Counts the aaa Statistics count and displays in the log
+ countAaaStatistics();
- assertNotEquals(aaaStatisticsManager.getAaaStats().getAcceptResponsesRx(), ZERO);
- assertNotEquals(aaaStatisticsManager.getAaaStats().getAccessRequestsTx(), ZERO);
- assertNotEquals(aaaStatisticsManager.getAaaStats().getChallengeResponsesRx(), ZERO);
- assertNotEquals(aaaStatisticsManager.getAaaStats().getDroppedResponsesRx(), ZERO);
- assertNotEquals(aaaStatisticsManager.getAaaStats().getInvalidValidatorsRx(), ZERO);
- assertNotEquals(aaaStatisticsManager.getAaaStats().getPendingRequests(), ZERO);
-
- // Counts the aaa Statistics count and displays in the log
- countAaaStatistics();
}
+ /** Tests invalid packets reaching AAA.
+ * And counts the aaa Stats for successful transmission.
+ * @throws DeserializationException
+ * if packed deserialization fails.
+ */
+ @Test
+ public void testStatisticsForInvalidPackets() throws Exception {
+
+ //Test Authenticator State Machine Status. Should be Pending
+ // (1) Supplicant start up
+ Ethernet startPacket = constructSupplicantStartPacket();
+ sendPacket(startPacket);
+
+ Ethernet responsePacket = (Ethernet) fetchPacket(0);
+ checkRadiusPacket(aaaManager, responsePacket, EAP.ATTR_IDENTITY);
+
+ // (2) Supplicant identify
+
+ Ethernet identifyPacket = constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null);
+ sendPacket(identifyPacket);
+
+ RADIUS radiusIdentifyPacket = (RADIUS) fetchPacket(1);
+ checkRadiusPacketFromSupplicant(radiusIdentifyPacket);
+
+ assertThat(radiusIdentifyPacket.getCode(), is(RADIUS.RADIUS_CODE_ACCESS_REQUEST));
+ assertThat(new String(radiusIdentifyPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME).getValue()),
+ is("testuser"));
+ IpAddress nasIp = IpAddress.valueOf(IpAddress.Version.INET,
+ radiusIdentifyPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP).getValue());
+ assertThat(nasIp.toString(), is(aaaManager.nasIpAddress.getHostAddress()));
+
+ // State machine should have been created by now
+
+ StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(SESSION_ID);
+ assertThat(stateMachine, notNullValue());
+ assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING));
+
+ // (3) RADIUS NAK challenge
+
+ RADIUS radiusCodeAccessChallengePacket = constructRadiusCodeAccessChallengePacket(
+ RADIUS.RADIUS_CODE_ACCESS_CHALLENGE, EAP.ATTR_NAK);
+ aaaManager.handleRadiusPacket(radiusCodeAccessChallengePacket);
+
+ Ethernet radiusChallengeNakPacket = (Ethernet) fetchPacket(2);
+ checkRadiusPacket(aaaManager, radiusChallengeNakPacket, EAP.ATTR_NAK);
+
+ // (4) Supplicant NAK response
+
+ Ethernet nakRadiusPacket = constructSupplicantIdentifyPacket(stateMachine, EAP.ATTR_NAK,
+ stateMachine.challengeIdentifier(), radiusChallengeNakPacket);
+ sendPacket(nakRadiusPacket);
+
+ //Statistic Should be increased.
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getPendingResSupp(), ZERO);
+
+ //Test if packet with invalid eapol type recieved.
+ // Supplicant ASF Packet
+ Ethernet invalidPacket = constructSupplicantAsfPacket();
+ sendPacket(invalidPacket);
+
+ //Statistic Should be increased.
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getInvalidPktType(), ZERO);
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getAccessRequestsTx(), ZERO);
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getChallengeResponsesRx(), ZERO);
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getDroppedResponsesRx(), ZERO);
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getInvalidValidatorsRx(), ZERO);
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getPendingRequests(), ZERO);
+
+ // Counts the aaa Statistics count and displays in the log
+ countAaaStatistics();
+ }
+
+
/** Tests the count for defected packets.
*
* @throws DeserializationException
@@ -563,7 +636,8 @@
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolStartReqTrans(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolTransRespNotNak(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapPktTxauthChooseEap(), ZERO);
- // Counts the aaa Statistics count
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getAuthStateIdle(), ZERO);
+ // Counts the aaa Statistics count
countAaaStatistics();
}
diff --git a/app/src/test/java/org/opencord/aaa/impl/AaaTestBase.java b/app/src/test/java/org/opencord/aaa/impl/AaaTestBase.java
index 14f1258..98bce71 100644
--- a/app/src/test/java/org/opencord/aaa/impl/AaaTestBase.java
+++ b/app/src/test/java/org/opencord/aaa/impl/AaaTestBase.java
@@ -427,6 +427,33 @@
}
/**
+ * Constructs an Ethernet packet containing a EAPOL_ASF Payload.
+ *
+ * @return Ethernet packet
+ */
+ Ethernet constructSupplicantAsfPacket() {
+ Ethernet eth = new Ethernet();
+ eth.setDestinationMACAddress(clientMac.toBytes());
+ eth.setSourceMACAddress(serverMac.toBytes());
+ eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort());
+ eth.setVlanID((short) 2);
+
+ EAP eap = new EAP(EAPOL.EAPOL_START, (byte) 3, EAPOL.EAPOL_START, null);
+
+ // eapol header
+ EAPOL eapol = new EAPOL();
+ eapol.setEapolType(EAPOL.EAPOL_ASF);
+ eapol.setPacketLength(eap.getLength());
+
+ // eap part
+ eapol.setPayload(eap);
+
+ eth.setPayload(eapol);
+ eth.setPad(true);
+ return eth;
+ }
+
+ /**
* Checks the contents of a RADIUS packet being sent to the RADIUS server.
*
* @param radiusPacket packet to check