xref: /OpenGrok/plugins/src/test/java/opengrok/auth/plugin/decoders/MellonDecoderTest.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 
30b28a5538SAdam Hornacek import static opengrok.auth.plugin.decoders.MellonHeaderDecoder.MELLON_EMAIL_HEADER;
315880dabeSVladimir Kotal import static opengrok.auth.plugin.decoders.MellonHeaderDecoder.MELLON_USERNAME_HEADER;
32*2f7dccc7SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertEquals;
33*2f7dccc7SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertFalse;
34*2f7dccc7SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertNotNull;
35*2f7dccc7SAdam Hornacek import static org.junit.jupiter.api.Assertions.assertNull;
36b28a5538SAdam Hornacek 
37b28a5538SAdam Hornacek public class MellonDecoderTest {
38b28a5538SAdam Hornacek     DummyHttpServletRequestUser dummyRequest;
39b28a5538SAdam Hornacek     MellonHeaderDecoder decoder = new MellonHeaderDecoder();
40b28a5538SAdam Hornacek 
41*2f7dccc7SAdam Hornacek     @BeforeEach
setUp()42b28a5538SAdam Hornacek     public void setUp() {
43b28a5538SAdam Hornacek         dummyRequest = new DummyHttpServletRequestUser();
44b28a5538SAdam Hornacek         dummyRequest.setHeader(MELLON_EMAIL_HEADER, "foo@bar.cz");
45b28a5538SAdam Hornacek     }
46b28a5538SAdam Hornacek 
47b28a5538SAdam Hornacek     @Test
testId()485880dabeSVladimir Kotal     public void testId() {
49b28a5538SAdam Hornacek         User result = decoder.fromRequest(dummyRequest);
50b28a5538SAdam Hornacek 
51*2f7dccc7SAdam Hornacek         assertNotNull(result);
52*2f7dccc7SAdam Hornacek         assertEquals("foo@bar.cz", result.getId());
535880dabeSVladimir Kotal         assertNull(result.getUsername());
54*2f7dccc7SAdam Hornacek         assertFalse(result.isTimeouted());
55b28a5538SAdam Hornacek     }
56b28a5538SAdam Hornacek 
57b28a5538SAdam Hornacek     @Test
testMissingHeader()58b28a5538SAdam Hornacek     public void testMissingHeader() {
59b28a5538SAdam Hornacek         assertNull(decoder.fromRequest(new DummyHttpServletRequestUser()));
60b28a5538SAdam Hornacek     }
615880dabeSVladimir Kotal 
625880dabeSVladimir Kotal     @Test
testUsername()635880dabeSVladimir Kotal     public void testUsername() {
645880dabeSVladimir Kotal         dummyRequest.setHeader(MELLON_USERNAME_HEADER, "foo");
655880dabeSVladimir Kotal         User result = decoder.fromRequest(dummyRequest);
665880dabeSVladimir Kotal 
67*2f7dccc7SAdam Hornacek         assertNotNull(result);
68*2f7dccc7SAdam Hornacek         assertEquals("foo", result.getUsername());
69*2f7dccc7SAdam Hornacek         assertFalse(result.isTimeouted());
705880dabeSVladimir Kotal     }
71b28a5538SAdam Hornacek }
72