blob: f19e4a693f6b962c0edcf0668bc5bff2b65bed00 [file] [log] [blame]
Jian Lif8c2d4a2016-09-15 02:33:12 +09001/*
2 * Copyright 2016-present Open Networking Laboratory
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 */
16package org.onosproject.lisp.msg.authentication;
17
18import org.junit.Before;
19import org.junit.Test;
20
21import static org.hamcrest.MatcherAssert.assertThat;
22import static org.hamcrest.Matchers.is;
Jian Li5e505c62016-12-05 02:44:24 +090023import static org.onosproject.lisp.msg.authentication.LispAuthenticationKeyEnum.NONE;
24import static org.onosproject.lisp.msg.authentication.LispAuthenticationKeyEnum.SHA1;
25import static org.onosproject.lisp.msg.authentication.LispAuthenticationKeyEnum.SHA256;
26import static org.onosproject.lisp.msg.authentication.LispAuthenticationKeyEnum.UNKNOWN;
Jian Lif8c2d4a2016-09-15 02:33:12 +090027
28/**
29 * Test case for LISP authentication.
30 */
31public class LispAuthenticationTest {
32
33 private LispAuthenticationFactory factory;
34
35 @Before
36 public void setup() {
37 factory = LispAuthenticationFactory.getInstance();
38 }
39
40 @Test
41 public void testAuthData() {
42
43 String authKey = "testKey";
Jian Liafe2d3f2016-11-01 02:49:07 +090044 byte[] noneAuthData = factory.createAuthenticationData(NONE, authKey, new byte[0]);
45 byte[] unknownAuthData = factory.createAuthenticationData(UNKNOWN, authKey, new byte[0]);
46 byte[] sha1AuthData = factory.createAuthenticationData(SHA1, authKey, new byte[0]);
47 byte[] sha256AuthData = factory.createAuthenticationData(SHA256, authKey, new byte[0]);
Jian Lif8c2d4a2016-09-15 02:33:12 +090048
49 assertThat(noneAuthData, is(new byte[0]));
50 assertThat(unknownAuthData, is(new byte[0]));
51 assertThat(sha1AuthData.length, is(20));
52 assertThat(sha256AuthData.length, is(32));
53 }
Jian Li5b2b2362016-11-27 17:38:19 +090054
55 @Test(expected = IllegalArgumentException.class)
56 public void testInvalidAuthType() {
57 LispAuthenticationKeyEnum authType = LispAuthenticationKeyEnum.valueOf((short) 0);
58 LispMacAuthentication macAuth = new LispMacAuthentication(authType);
59
60 macAuth.getAuthenticationData("onos", new byte[0]);
61 }
62
63 @Test(expected = NullPointerException.class)
64 public void testNullAuthKey() {
65 LispAuthenticationKeyEnum authType = LispAuthenticationKeyEnum.valueOf((short) 1);
66
67 LispMacAuthentication macAuth = new LispMacAuthentication(authType);
68 macAuth.getAuthenticationData(null, new byte[0]);
69 }
70
71 @Test(expected = IllegalArgumentException.class)
72 public void testInvalidAuthKey() {
73 LispAuthenticationKeyEnum authType = LispAuthenticationKeyEnum.valueOf((short) 1);
74
75 LispMacAuthentication macAuth = new LispMacAuthentication(authType);
76 macAuth.getAuthenticationData("", new byte[0]);
77 }
Jian Lif8c2d4a2016-09-15 02:33:12 +090078}