blob: 414670dcf7f0063a31ac7514ebebd454ea9ba8fb [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;
23import static org.onosproject.lisp.msg.authentication.LispAuthenticationKeyEnum.*;
24
25/**
26 * Test case for LISP authentication.
27 */
28public class LispAuthenticationTest {
29
30 private LispAuthenticationFactory factory;
31
32 @Before
33 public void setup() {
34 factory = LispAuthenticationFactory.getInstance();
35 }
36
37 @Test
38 public void testAuthData() {
39
40 String authKey = "testKey";
Jian Liafe2d3f2016-11-01 02:49:07 +090041 byte[] noneAuthData = factory.createAuthenticationData(NONE, authKey, new byte[0]);
42 byte[] unknownAuthData = factory.createAuthenticationData(UNKNOWN, authKey, new byte[0]);
43 byte[] sha1AuthData = factory.createAuthenticationData(SHA1, authKey, new byte[0]);
44 byte[] sha256AuthData = factory.createAuthenticationData(SHA256, authKey, new byte[0]);
Jian Lif8c2d4a2016-09-15 02:33:12 +090045
46 assertThat(noneAuthData, is(new byte[0]));
47 assertThat(unknownAuthData, is(new byte[0]));
48 assertThat(sha1AuthData.length, is(20));
49 assertThat(sha256AuthData.length, is(32));
50 }
Jian Li5b2b2362016-11-27 17:38:19 +090051
52 @Test(expected = IllegalArgumentException.class)
53 public void testInvalidAuthType() {
54 LispAuthenticationKeyEnum authType = LispAuthenticationKeyEnum.valueOf((short) 0);
55 LispMacAuthentication macAuth = new LispMacAuthentication(authType);
56
57 macAuth.getAuthenticationData("onos", new byte[0]);
58 }
59
60 @Test(expected = NullPointerException.class)
61 public void testNullAuthKey() {
62 LispAuthenticationKeyEnum authType = LispAuthenticationKeyEnum.valueOf((short) 1);
63
64 LispMacAuthentication macAuth = new LispMacAuthentication(authType);
65 macAuth.getAuthenticationData(null, new byte[0]);
66 }
67
68 @Test(expected = IllegalArgumentException.class)
69 public void testInvalidAuthKey() {
70 LispAuthenticationKeyEnum authType = LispAuthenticationKeyEnum.valueOf((short) 1);
71
72 LispMacAuthentication macAuth = new LispMacAuthentication(authType);
73 macAuth.getAuthenticationData("", new byte[0]);
74 }
Jian Lif8c2d4a2016-09-15 02:33:12 +090075}