1b5521af9SChris Fraire /* 2b5521af9SChris Fraire * CDDL HEADER START 3b5521af9SChris Fraire * 4b5521af9SChris Fraire * The contents of this file are subject to the terms of the 5b5521af9SChris Fraire * Common Development and Distribution License (the "License"). 6b5521af9SChris Fraire * You may not use this file except in compliance with the License. 7b5521af9SChris Fraire * 8b5521af9SChris Fraire * See LICENSE.txt included in this distribution for the specific 9b5521af9SChris Fraire * language governing permissions and limitations under the License. 10b5521af9SChris Fraire * 11b5521af9SChris Fraire * When distributing Covered Code, include this CDDL HEADER in each 12b5521af9SChris Fraire * file and include the License file at LICENSE.txt. 13b5521af9SChris Fraire * If applicable, add the following below this CDDL HEADER, with the 14b5521af9SChris Fraire * fields enclosed by brackets "[]" replaced with your own identifying 15b5521af9SChris Fraire * information: Portions Copyright [yyyy] [name of copyright owner] 16b5521af9SChris Fraire * 17b5521af9SChris Fraire * CDDL HEADER END 18b5521af9SChris Fraire */ 19b5521af9SChris Fraire 20b5521af9SChris Fraire /* 21b5521af9SChris Fraire * Copyright (c) 2020, Chris Fraire <cfraire@me.com>. 22b5521af9SChris Fraire */ 23b5521af9SChris Fraire package opengrok.auth.plugin; 24b5521af9SChris Fraire 25b5521af9SChris Fraire import opengrok.auth.plugin.entity.User; 262f7dccc7SAdam Hornacek import org.junit.jupiter.api.BeforeEach; 272f7dccc7SAdam Hornacek import org.junit.jupiter.api.Test; 28b5521af9SChris Fraire import org.opengrok.indexer.configuration.Group; 29b5521af9SChris Fraire import org.opengrok.indexer.configuration.Project; 30b5521af9SChris Fraire import org.opengrok.indexer.util.RandomString; 31b5521af9SChris Fraire import org.opengrok.indexer.web.DummyHttpServletRequest; 32b5521af9SChris Fraire 33*14bb522cSAdam Hornacek import static org.junit.jupiter.api.Assertions.assertFalse; 34b5521af9SChris Fraire 35b5521af9SChris Fraire /** 36b5521af9SChris Fraire * Represents a container for tests of {@link FalsePlugin}. 37b5521af9SChris Fraire */ 38*14bb522cSAdam Hornacek class FalsePluginTest { 39b5521af9SChris Fraire 40b5521af9SChris Fraire private FalsePlugin plugin; 41b5521af9SChris Fraire 422f7dccc7SAdam Hornacek @BeforeEach setUp()43b5521af9SChris Fraire public void setUp() { 44b5521af9SChris Fraire plugin = new FalsePlugin(); 45b5521af9SChris Fraire } 46b5521af9SChris Fraire 47b5521af9SChris Fraire @Test shouldNotThrowOnLoadIfNullArgument()48*14bb522cSAdam Hornacek void shouldNotThrowOnLoadIfNullArgument() { 49b5521af9SChris Fraire plugin.load(null); 50b5521af9SChris Fraire } 51b5521af9SChris Fraire 52b5521af9SChris Fraire @Test shouldUnload()53*14bb522cSAdam Hornacek void shouldUnload() { 54b5521af9SChris Fraire plugin.unload(); 55b5521af9SChris Fraire } 56b5521af9SChris Fraire 57b5521af9SChris Fraire @Test shouldNotAllowRandomUserForAnyProject()58*14bb522cSAdam Hornacek void shouldNotAllowRandomUserForAnyProject() { 59b5521af9SChris Fraire DummyHttpServletRequest req = new DummyHttpServletRequest(); 60b5521af9SChris Fraire req.setAttribute(UserPlugin.REQUEST_ATTR, new User(RandomString.generateUpper(8))); 61b5521af9SChris Fraire 62b5521af9SChris Fraire Project randomProject = new Project(RandomString.generateUpper(10)); 63b5521af9SChris Fraire boolean projectAllowed = plugin.isAllowed(req, randomProject); 64*14bb522cSAdam Hornacek assertFalse(projectAllowed, "should not allow rando for random project 1"); 65b5521af9SChris Fraire 66b5521af9SChris Fraire randomProject = new Project(RandomString.generateUpper(10)); 67b5521af9SChris Fraire projectAllowed = plugin.isAllowed(req, randomProject); 68*14bb522cSAdam Hornacek assertFalse(projectAllowed, "should not allow rando for random project 2"); 69b5521af9SChris Fraire } 70b5521af9SChris Fraire 71b5521af9SChris Fraire @Test shouldNotAllowRandomUserForAnyGroup()72*14bb522cSAdam Hornacek void shouldNotAllowRandomUserForAnyGroup() { 73b5521af9SChris Fraire DummyHttpServletRequest req = new DummyHttpServletRequest(); 74b5521af9SChris Fraire req.setAttribute(UserPlugin.REQUEST_ATTR, new User(RandomString.generateUpper(8))); 75b5521af9SChris Fraire 76b5521af9SChris Fraire Group randomGroup = new Group(RandomString.generateUpper(10)); 77b5521af9SChris Fraire boolean projectAllowed = plugin.isAllowed(req, randomGroup); 78*14bb522cSAdam Hornacek assertFalse(projectAllowed, "should not allow rando for random group 1"); 79b5521af9SChris Fraire 80b5521af9SChris Fraire randomGroup = new Group(RandomString.generateUpper(10)); 81b5521af9SChris Fraire projectAllowed = plugin.isAllowed(req, randomGroup); 82*14bb522cSAdam Hornacek assertFalse(projectAllowed, "should not allow rando for random group 2"); 83b5521af9SChris Fraire } 84b5521af9SChris Fraire } 85