xref: /OpenGrok/plugins/src/test/java/opengrok/auth/plugin/decoders/UserPrincipalDecoderTest.java (revision 2f7dccc7cd05ce1957006b093948d5359068ae4f)
1b28a5538SAdam Hornacek /*
2b28a5538SAdam Hornacek  * CDDL HEADER START
3b28a5538SAdam Hornacek  *
4b28a5538SAdam Hornacek  * The contents of this file are subject to the terms of the
5b28a5538SAdam Hornacek  * Common Development and Distribution License (the "License").
6b28a5538SAdam Hornacek  * You may not use this file except in compliance with the License.
7b28a5538SAdam Hornacek  *
8b28a5538SAdam Hornacek  * See LICENSE.txt included in this distribution for the specific
9b28a5538SAdam Hornacek  * language governing permissions and limitations under the License.
10b28a5538SAdam Hornacek  *
11b28a5538SAdam Hornacek  * When distributing Covered Code, include this CDDL HEADER in each
12b28a5538SAdam Hornacek  * file and include the License file at LICENSE.txt.
13b28a5538SAdam Hornacek  * If applicable, add the following below this CDDL HEADER, with the
14b28a5538SAdam Hornacek  * fields enclosed by brackets "[]" replaced with your own identifying
15b28a5538SAdam Hornacek  * information: Portions Copyright [yyyy] [name of copyright owner]
16b28a5538SAdam Hornacek  *
17b28a5538SAdam Hornacek  * CDDL HEADER END
18b28a5538SAdam Hornacek  */
19b28a5538SAdam Hornacek 
20b28a5538SAdam Hornacek /*
21*2f7dccc7SAdam Hornacek  * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
22b28a5538SAdam Hornacek  */
23b28a5538SAdam Hornacek package opengrok.auth.plugin.decoders;
24b28a5538SAdam Hornacek 
25b28a5538SAdam Hornacek import opengrok.auth.plugin.entity.User;
26b28a5538SAdam Hornacek import opengrok.auth.plugin.util.DummyHttpServletRequestUser;
27*2f7dccc7SAdam Hornacek import org.junit.jupiter.api.BeforeEach;
28*2f7dccc7SAdam Hornacek import org.junit.jupiter.api.Test;
29b28a5538SAdam Hornacek 
30*2f7dccc7SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertEquals;
31*2f7dccc7SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertFalse;
32*2f7dccc7SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertNotNull;
33*2f7dccc7SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertNull;
34b28a5538SAdam Hornacek 
35b28a5538SAdam Hornacek public class UserPrincipalDecoderTest {
36b28a5538SAdam Hornacek     DummyHttpServletRequestUser dummyRequest;
37b28a5538SAdam Hornacek     UserPrincipalDecoder decoder = new UserPrincipalDecoder();
38b28a5538SAdam Hornacek 
39*2f7dccc7SAdam Hornacek     @BeforeEach
setUp()40b28a5538SAdam Hornacek     public void setUp() {
41b28a5538SAdam Hornacek         dummyRequest = new DummyHttpServletRequestUser();
42b28a5538SAdam Hornacek     }
43b28a5538SAdam Hornacek 
44b28a5538SAdam Hornacek     @Test
testHttpBasicDecoding()45b28a5538SAdam Hornacek     public void testHttpBasicDecoding() {
46b28a5538SAdam Hornacek         dummyRequest.setHeader("authorization", "Basic Zm9vOmJhcg==");
47b28a5538SAdam Hornacek 
48b28a5538SAdam Hornacek         User result = decoder.fromRequest(dummyRequest);
49b28a5538SAdam Hornacek 
50*2f7dccc7SAdam Hornacek         assertNotNull(result);
51*2f7dccc7SAdam Hornacek         assertEquals("foo", result.getUsername());
52b28a5538SAdam Hornacek         assertNull(result.getId());
53*2f7dccc7SAdam Hornacek         assertFalse(result.isTimeouted());
54b28a5538SAdam Hornacek     }
55b28a5538SAdam Hornacek 
56b28a5538SAdam Hornacek     @Test
testMissingHeader()57b28a5538SAdam Hornacek     public void testMissingHeader() {
58b28a5538SAdam Hornacek         assertNull(decoder.fromRequest(new DummyHttpServletRequestUser()));
59b28a5538SAdam Hornacek     }
60b28a5538SAdam Hornacek }
61b28a5538SAdam Hornacek 
62