1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package waffle.apache;
25
26 import java.io.IOException;
27
28 import javax.servlet.http.HttpServletResponse;
29
30 import org.apache.catalina.connector.Request;
31 import org.junit.jupiter.api.Assertions;
32 import org.junit.jupiter.api.BeforeEach;
33 import org.junit.jupiter.api.Test;
34 import org.slf4j.LoggerFactory;
35
36
37
38
39 class WaffleAuthenticatorBaseTest {
40
41
42 private WaffleAuthenticatorBase waffleAuthenticatorBase;
43
44
45
46
47 @BeforeEach
48 void init() {
49 this.waffleAuthenticatorBase = new WaffleAuthenticatorBase() {
50 {
51 this.log = LoggerFactory.getLogger(WaffleAuthenticatorBaseTest.class);
52 }
53
54 @Override
55 public boolean authenticate(final Request request, final HttpServletResponse response) throws IOException {
56 return false;
57 }
58
59 @Override
60 protected boolean doAuthenticate(final Request request, final HttpServletResponse response)
61 throws IOException {
62 return false;
63 }
64 };
65 }
66
67
68
69
70 @Test
71 void should_accept_both_protocols() {
72 this.waffleAuthenticatorBase.setProtocols(" NTLM , , Negotiate ");
73
74 Assertions.assertEquals(2, this.waffleAuthenticatorBase.protocols.size(), "Two protocols added");
75 Assertions.assertTrue(this.waffleAuthenticatorBase.protocols.contains("NTLM"), "NTLM has been added");
76 Assertions.assertTrue(this.waffleAuthenticatorBase.protocols.contains("Negotiate"), "Negotiate has been added");
77 }
78
79
80
81
82 @Test
83 void should_accept_Negotiate_protocol() {
84 this.waffleAuthenticatorBase.setProtocols(" Negotiate ");
85
86 Assertions.assertEquals(1, this.waffleAuthenticatorBase.protocols.size(), "One protocol added");
87 Assertions.assertEquals("Negotiate", this.waffleAuthenticatorBase.protocols.iterator().next());
88 }
89
90
91
92
93 @Test
94 void should_accept_NTLM_protocol() {
95 this.waffleAuthenticatorBase.setProtocols(" NTLM ");
96
97 Assertions.assertEquals(1, this.waffleAuthenticatorBase.protocols.size(), "One protocol added");
98 Assertions.assertEquals("NTLM", this.waffleAuthenticatorBase.protocols.iterator().next());
99 }
100
101
102
103
104 @Test
105 void should_refuse_other_protocol() {
106 Assertions.assertThrows(RuntimeException.class, () -> {
107 this.waffleAuthenticatorBase.setProtocols(" NTLM , OTHER, Negotiate ");
108 });
109 }
110
111 }