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; 26*6c62ede9SAdam Hornacek import org.apache.commons.lang3.RandomStringUtils; 272f7dccc7SAdam Hornacek import org.junit.jupiter.api.BeforeEach; 282f7dccc7SAdam Hornacek import org.junit.jupiter.api.Test; 29b5521af9SChris Fraire import org.opengrok.indexer.configuration.Group; 30b5521af9SChris Fraire import org.opengrok.indexer.configuration.Project; 31b5521af9SChris Fraire import org.opengrok.indexer.web.DummyHttpServletRequest; 32b5521af9SChris Fraire 3314bb522cSAdam 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 */ 3814bb522cSAdam 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()4814bb522cSAdam Hornacek void shouldNotThrowOnLoadIfNullArgument() { 49b5521af9SChris Fraire plugin.load(null); 50b5521af9SChris Fraire } 51b5521af9SChris Fraire 52b5521af9SChris Fraire @Test shouldUnload()5314bb522cSAdam Hornacek void shouldUnload() { 54b5521af9SChris Fraire plugin.unload(); 55b5521af9SChris Fraire } 56b5521af9SChris Fraire 57b5521af9SChris Fraire @Test shouldNotAllowRandomUserForAnyProject()5814bb522cSAdam Hornacek void shouldNotAllowRandomUserForAnyProject() { 59b5521af9SChris Fraire DummyHttpServletRequest req = new DummyHttpServletRequest(); 60*6c62ede9SAdam Hornacek req.setAttribute(UserPlugin.REQUEST_ATTR, new User(RandomStringUtils.randomAlphanumeric(8))); 61b5521af9SChris Fraire 62*6c62ede9SAdam Hornacek Project randomProject = new Project(RandomStringUtils.randomAlphanumeric(10)); 63b5521af9SChris Fraire boolean projectAllowed = plugin.isAllowed(req, randomProject); 6414bb522cSAdam Hornacek assertFalse(projectAllowed, "should not allow rando for random project 1"); 65b5521af9SChris Fraire 66*6c62ede9SAdam Hornacek randomProject = new Project(RandomStringUtils.randomAlphanumeric(10)); 67b5521af9SChris Fraire projectAllowed = plugin.isAllowed(req, randomProject); 6814bb522cSAdam Hornacek assertFalse(projectAllowed, "should not allow rando for random project 2"); 69b5521af9SChris Fraire } 70b5521af9SChris Fraire 71b5521af9SChris Fraire @Test shouldNotAllowRandomUserForAnyGroup()7214bb522cSAdam Hornacek void shouldNotAllowRandomUserForAnyGroup() { 73b5521af9SChris Fraire DummyHttpServletRequest req = new DummyHttpServletRequest(); 74*6c62ede9SAdam Hornacek req.setAttribute(UserPlugin.REQUEST_ATTR, new User(RandomStringUtils.randomAlphanumeric(8))); 75b5521af9SChris Fraire 76*6c62ede9SAdam Hornacek Group randomGroup = new Group(RandomStringUtils.randomAlphanumeric(10)); 77b5521af9SChris Fraire boolean projectAllowed = plugin.isAllowed(req, randomGroup); 7814bb522cSAdam Hornacek assertFalse(projectAllowed, "should not allow rando for random group 1"); 79b5521af9SChris Fraire 80*6c62ede9SAdam Hornacek randomGroup = new Group(RandomStringUtils.randomAlphanumeric(10)); 81b5521af9SChris Fraire projectAllowed = plugin.isAllowed(req, randomGroup); 8214bb522cSAdam Hornacek assertFalse(projectAllowed, "should not allow rando for random group 2"); 83b5521af9SChris Fraire } 84b5521af9SChris Fraire } 85