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.spring;
25  
26  import org.junit.jupiter.api.Assertions;
27  import org.junit.jupiter.api.BeforeEach;
28  import org.junit.jupiter.api.Test;
29  import org.springframework.security.core.authority.SimpleGrantedAuthority;
30  
31  import waffle.mock.MockWindowsAccount;
32  import waffle.windows.auth.WindowsAccount;
33  
34  /**
35   * The Class FqnGrantedAuthorityFactoryTest.
36   */
37  class FqnGrantedAuthorityFactoryTest {
38  
39      /** The group. */
40      private WindowsAccount group;
41  
42      /**
43       * Sets the up.
44       */
45      @BeforeEach
46      void setUp() {
47          this.group = new WindowsAccount(new MockWindowsAccount("group"));
48      }
49  
50      /**
51       * Test prefix and uppercase.
52       */
53      @Test
54      void testPrefixAndUppercase() {
55          final FqnGrantedAuthorityFactory factory = new FqnGrantedAuthorityFactory("prefix_", true);
56          Assertions.assertEquals(new SimpleGrantedAuthority("PREFIX_GROUP"), factory.createGrantedAuthority(this.group));
57      }
58  
59      /**
60       * Test prefix and lowercase.
61       */
62      @Test
63      void testPrefixAndLowercase() {
64          final FqnGrantedAuthorityFactory factory = new FqnGrantedAuthorityFactory("prefix_", false);
65          Assertions.assertEquals(new SimpleGrantedAuthority("prefix_group"), factory.createGrantedAuthority(this.group));
66      }
67  
68      /**
69       * Test no prefix and uppercase.
70       */
71      @Test
72      void testNoPrefixAndUppercase() {
73          final FqnGrantedAuthorityFactory factory = new FqnGrantedAuthorityFactory(null, true);
74          Assertions.assertEquals(new SimpleGrantedAuthority("GROUP"), factory.createGrantedAuthority(this.group));
75      }
76  
77      /**
78       * Test no prefix and lowercase.
79       */
80      @Test
81      void testNoPrefixAndLowercase() {
82          final FqnGrantedAuthorityFactory factory = new FqnGrantedAuthorityFactory(null, false);
83          Assertions.assertEquals(new SimpleGrantedAuthority("group"), factory.createGrantedAuthority(this.group));
84      }
85  
86  }