View Javadoc
1   /*
2    * MIT License
3    *
4    * Copyright (c) 2010-2020 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy
7    * of this software and associated documentation files (the "Software"), to deal
8    * in the Software without restriction, including without limitation the rights
9    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10   * copies of the Software, and to permit persons to whom the Software is
11   * furnished to do so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  package waffle.util;
25  
26  import org.junit.jupiter.api.Assertions;
27  import org.junit.jupiter.api.Test;
28  
29  /**
30   * The Class SPNegoMessageTest.
31   *
32   * @author ari.suutari[at]syncrontech[dot]com
33   */
34  class SPNegoMessageTest {
35  
36      // Different SPNEGO messages. For details and specification,
37      // see https://msdn.microsoft.com/en-us/library/ms995330.aspx
38  
39      /** The Constant negTokenInitOk. */
40      private static final byte[] negTokenInitOk = { 0x60, 0x76, 0x06, 0x06, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x02 };
41  
42      /** The Constant negTokenInitTooShort. */
43      private static final byte[] negTokenInitTooShort = { 0x60, 0x76, 0x06, 0x06, 0x2B, 0x06, 0x01, 0x05, 0x05 };
44  
45      /** The Constant negTokenArgOk. */
46      private static final byte[] negTokenArgOk = { (byte) 0xA1, 0x33, 0x30, 0x31, 0x0, 0x03, 0x0A, 0x01, 0x01, 0x0, 0x2A,
47              0x04, 0x28, 0x4E, 0x54, 0x4C, 0x4D, 0x53, 0x53, 0x50, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0, 0x0, 0x08, 0x0,
48              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x01,
49              0x0, 0x1D, 0x00, 0x00, 0x00, 0x0F };
50  
51      /** The Constant negTokenArgTooShort. */
52      private static final byte[] negTokenArgTooShort = { (byte) 0xA1, 0x33, 0x30, 0x31, 0x0, 0x03 };
53  
54      /** The Constant badMessage. */
55      private static final byte[] badMessage = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
56  
57      /**
58       * Test is neg token init.
59       */
60      @Test
61      void testIsNegTokenInit() {
62          Assertions.assertTrue(SPNegoMessage.isNegTokenInit(SPNegoMessageTest.negTokenInitOk));
63          Assertions.assertFalse(SPNegoMessage.isNegTokenInit(SPNegoMessageTest.negTokenInitTooShort));
64          Assertions.assertFalse(SPNegoMessage.isNegTokenInit(SPNegoMessageTest.badMessage));
65      }
66  
67      /**
68       * Test is neg token arg.
69       */
70      @Test
71      void testIsNegTokenArg() {
72          Assertions.assertTrue(SPNegoMessage.isNegTokenArg(SPNegoMessageTest.negTokenArgOk));
73          Assertions.assertFalse(SPNegoMessage.isNegTokenArg(SPNegoMessageTest.negTokenArgTooShort));
74          Assertions.assertFalse(SPNegoMessage.isNegTokenArg(SPNegoMessageTest.badMessage));
75      }
76  }