|
| 1 | +/* |
| 2 | + * Copyright (c) 2000, 2025, Oracle and/or its affiliates. |
| 3 | + * |
| 4 | + * Licensed under the Universal Permissive License v 1.0 as shown at |
| 5 | + * https://oss.oracle.com/licenses/upl. |
| 6 | + */ |
| 7 | +package extend; |
| 8 | + |
| 9 | +import java.util.Properties; |
| 10 | +import org.junit.AfterClass; |
| 11 | +import org.junit.BeforeClass; |
| 12 | +import org.junit.Test; |
| 13 | + |
| 14 | +import com.oracle.coherence.testing.AbstractFunctionalTest; |
| 15 | + |
| 16 | +import static org.junit.Assert.*; |
| 17 | + |
| 18 | +/** |
| 19 | + * A collection of functional tests for a Coherence*Extend proxy that uses |
| 20 | + * system property coherence.extend.authorized hosts addresses and try to connect to an address that is not |
| 21 | + * authorized. |
| 22 | + * |
| 23 | + * @author jf 2025.04.17 |
| 24 | + */ |
| 25 | +public class AuthorizedHostsRejectedBySystemPropertyTests |
| 26 | + extends AbstractFunctionalTest |
| 27 | + { |
| 28 | + // ----- constructors --------------------------------------------------- |
| 29 | + |
| 30 | + /** |
| 31 | + * Default constructor. |
| 32 | + */ |
| 33 | + public AuthorizedHostsRejectedBySystemPropertyTests() |
| 34 | + { |
| 35 | + super(AbstractExtendTests.FILE_CLIENT_CFG_CACHE); |
| 36 | + } |
| 37 | + |
| 38 | + // ----- test lifecycle ------------------------------------------------- |
| 39 | + |
| 40 | + /** |
| 41 | + * Initialize the test class. |
| 42 | + */ |
| 43 | + @BeforeClass |
| 44 | + public static void startup() |
| 45 | + { |
| 46 | + Properties props = new Properties(); |
| 47 | + |
| 48 | + props.put("coherence.extend.authorized.hosts", "baddomain.bad,2.3.4.5"); |
| 49 | + startCacheServer("AuthorizedHostsRejectedBySystemPropertyTests", "extend", |
| 50 | + "authorized-hosts-cache-config-sysprop.xml", props); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Shutdown the test class. |
| 55 | + */ |
| 56 | + @AfterClass |
| 57 | + public static void shutdown() |
| 58 | + { |
| 59 | + stopCacheServer("AuthorizedHostsRejectedBySystemPropertyTests"); |
| 60 | + } |
| 61 | + |
| 62 | + // ----- AuthorizedHostsRejectedBySystemPropertyTests tests ----------------------------- |
| 63 | + |
| 64 | + /** |
| 65 | + * Ensure that non-authorized hosts fails. |
| 66 | + */ |
| 67 | + @Test |
| 68 | + public void connect() |
| 69 | + { |
| 70 | + try |
| 71 | + { |
| 72 | + getNamedCache("dist-extend-direct"); |
| 73 | + // we should not get here. If it does it means that an non-authorized host failed |
| 74 | + // to be rejected |
| 75 | + fail("Authorized hosts check did not work"); |
| 76 | + } |
| 77 | + catch (Exception e) |
| 78 | + { |
| 79 | + // this will cause an exception due to the unauthorized host. |
| 80 | + assertTrue("Did not get expected exception", e.getMessage().indexOf("could not establish a connection") != -1); |
| 81 | + } |
| 82 | + } |
| 83 | + } |
0 commit comments