io.dropwizard.jersey.validation.Validators Java Examples

The following examples show how to use io.dropwizard.jersey.validation.Validators. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Test
void testGetAuthFilters() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setKeyStore(null);

    final List<ContainerRequestFilter> filters = TrellisUtils.getAuthFilters(config);
    assertFalse(filters.isEmpty(), "Auth filters are missing!");
    assertEquals(2L, filters.size(), "Incorrect auth filter count!");

    config.getAuth().getBasic().setEnabled(false);
    config.getAuth().getJwt().setEnabled(false);

    assertTrue(TrellisUtils.getAuthFilters(config).isEmpty(), "Auth filters should have been disabled!");
}
 
Example #2
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Test
void testConfigurationAuth1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getAuth().getWebac().getEnabled(), "WebAC wasn't enabled!");
    assertEquals(100L, config.getAuth().getWebac().getCacheSize(), "Incorrect auth/webac/cacheSize value!");
    assertEquals(10L, config.getAuth().getWebac().getCacheExpireSeconds(), "Incorrect webac cache expiry!");
    assertTrue(config.getAuth().getBasic().getEnabled(), "Missing basic auth support!");
    assertEquals("users.auth", config.getAuth().getBasic().getUsersFile(), "Incorrect basic auth users file!");
    assertEquals("trellis", config.getAuth().getRealm(), "Incorrect auth realm!");

    config.getAuth().setRealm("foo");
    assertEquals("foo", config.getAuth().getRealm(), "Incorrect auth realm!");
    assertTrue(config.getAuth().getJwt().getEnabled(), "JWT not enabled!");
    assertEquals("xd1GuAwiP2+M+pyK+GlIUEAumSmFx5DP3dziGtVb1tA+/8oLXfSDMDZFkxVghyAd28rXImy18TmttUi+g0iomQ==",
            config.getAuth().getJwt().getKey(), "Incorrect JWT key!");

    assertEquals("password", config.getAuth().getJwt().getKeyStorePassword(), "Incorrect JWT keystore password!");
    assertEquals("/tmp/trellisData/keystore.jks", config.getAuth().getJwt().getKeyStore(), "Wrong keystore loc!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("foo"), "'foo' missing from JWT key ids!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("bar"), "'bar' missing from JWT key ids!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("trellis"), "'trellis' missing from JWT key ids!");
    assertEquals(3, config.getAuth().getJwt().getKeyIds().size(), "Incorrect JWT Key id count!");
}
 
Example #3
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 6 votes vote down vote up
@Test
void testGetWebacService() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    when(mockResourceService.get(any())).thenAnswer(inv -> completedFuture(mockResource));
    when(mockResource.getMetadataGraphNames()).thenReturn(singleton(Trellis.PreferAccessControl));

    assertNotNull(TrellisUtils.getWebacService(config, mockResourceService), "WebAC configuration not present!");

    config.getAuth().getWebac().setEnabled(false);

    assertNull(TrellisUtils.getWebacService(config, mockResourceService),
            "WebAC config persists after disabling it!");

    config.getAuth().getWebac().setEnabled(true);

    final ResourceService mockRS = mock(ResourceService.class, inv -> {
        throw new TrellisRuntimeException("expected");
    });
    assertThrows(TrellisRuntimeException.class, () -> TrellisUtils.getWebacService(config, mockRS));
    config.getAuth().getWebac().setEnabled(false);
    assertNull(TrellisUtils.getWebacService(config, mockRS),
            "WebAC config persists after disabling it!");
}
 
Example #4
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationCORS1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getCors().getEnabled(), "CORS not enabled!");
    assertTrue(config.getCors().getAllowOrigin().contains("*"), "'*' not in CORS allow-origin!");
    assertTrue(config.getCors().getAllowHeaders().contains("Link"), "Link not in CORS allow-headers");
    assertTrue(config.getCors().getAllowMethods().contains("PUT"), "PUT not in CORS allow-methods!");
    assertTrue(config.getCors().getExposeHeaders().contains("Memento-Datetime"),
            "memento-datetime missing from CORS expose-headers!");
    assertEquals(180, config.getCors().getMaxAge(), "Incorrect max-age value in CORS headers!");
    assertTrue(config.getCors().getAllowCredentials(), "Incorrect allow-credentials setting in CORS headers!");
}
 
Example #5
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetNoJwtAuthenticator() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setKeyStore(null);
    config.getAuth().getJwt().setKey("");
    config.getAuth().getJwt().setJwks(null);
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof NullAuthenticator,
            "JWT auth not disabled!");
}
 
Example #6
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationGeneral1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("Trellis", config.getDefaultName(), "Incorrect app name!");

    // Cache tests
    assertEquals(86400, config.getCache().getMaxAge(), "Incorrect cache/maxAge value!");
    assertFalse(config.getCache().getNoCache(), "Unexpected cache/noCache value!");
    assertTrue(config.getCache().getMustRevalidate(), "Missing cache/mustRevalidate value!");

    // JSON-LD tests
    assertEquals(48L, config.getJsonld().getCacheExpireHours(), "Incorrect jsonld/cacheExpireHours");
    assertEquals(10L, config.getJsonld().getCacheSize(), "Incorrect jsonld/cacheSize");
    assertTrue(config.getJsonld().getContextDomainWhitelist().isEmpty(), "Incorrect jsonld/contextDomainWhitelist");
    assertTrue(config.getJsonld().getContextWhitelist().contains("http://example.com/context.json"),
            "Incorrect jsonld/contextWhitelist value!");

    // Hub tests
    assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hubUrl");

    // Relative IRI configuration
    assertTrue(config.getUseRelativeIris(), "Incorrect relative IRI configuration");

    // Auth tests
    assertTrue(config.getAuth().getAdminUsers().contains("zoyd"), "zoyd missing from auth/adminUsers");
    assertTrue(config.getAuth().getAdminUsers().contains("wheeler"), "wheeler missing from auth/adminUsers");

    // Other tests
    assertEquals("my.cluster.address", config.any().get("cassandraAddress"), "Incorrect custom property!");
    assertEquals(245994, config.any().get("cassandraPort"), "Incorrect custom Integer property!");
    @SuppressWarnings("unchecked")
    final Map<String, Object> extraConfig = (Map<String, Object>) config.any().get("extraConfigValues");
    assertTrue((Boolean) extraConfig.get("first"), "Incorrect boolean nested custom properties!");
    @SuppressWarnings("unchecked")
    final List<String> list = (List<String>) extraConfig.get("second");
    assertEquals(newArrayList("val1", "val2"), list, "Incorrect nested custom properties as a List!");
}
 
Example #7
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationAssets1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    assertEquals("org/trellisldp/rdfa/resource.mustache", config.getAssets().getTemplate(), "Bad assets/template");
    assertEquals("http://example.com/image.icon", config.getAssets().getIcon(), "Bad assets/icon value!");
    assertTrue(config.getAssets().getJs().contains("http://example.com/scripts1.js"), "Missing assets/js value!");
    assertTrue(config.getAssets().getCss().contains("http://example.com/styles1.css"), "Missing assets/css value!");
}
 
Example #8
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationNotifications() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertFalse(config.getNotifications().getEnabled(), "Notifications unexpectedly enabled!");
    assertEquals(NotificationsConfiguration.Type.NONE, config.getNotifications().getType(),
            "Incorrect notification type!");
    assertEquals("example.com:12345", config.getNotifications().getConnectionString(), "Incorrect connection URL!");
    assertEquals("foo", config.getNotifications().any().get("some.other.value"), "Incorrect custom property!");
    assertEquals("test-topic", config.getNotifications().getTopicName(), "Incorrect topic name!");

}
 
Example #9
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationLocations() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("http://localhost:8080/", config.getBaseUrl(), "Incorrect baseUrl!");
    assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hubUrl!");
}
 
Example #10
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationAuth1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getAuth().getWebac().getEnabled(), "WebAC should be enabled!");
    assertEquals(200L, config.getAuth().getWebac().getCacheSize(), "Incorrect auth/webac/cacheSize");
    assertEquals(15L, config.getAuth().getWebac().getCacheExpireSeconds(), "Bad auth/webac/cache expiry!");
    assertTrue(config.getAuth().getBasic().getEnabled(), "basic auth not enabled!");
    assertEquals("users.auth", config.getAuth().getBasic().getUsersFile(), "Incorrect basic users file!");
    assertEquals("trellis", config.getAuth().getRealm(), "Incorrect auth realm!");
    assertEquals("openid", config.getAuth().getScope(), "Incorrect auth scope!");

    config.getAuth().setRealm("foobar");
    config.getAuth().setScope("baz");
    assertEquals("foobar", config.getAuth().getRealm(), "Incorrect auth/basic/realm value!");
    assertEquals("baz", config.getAuth().getScope(), "Incorrect auth scope!");
    assertTrue(config.getAuth().getJwt().getEnabled(), "auth/jwt not enabled!");
    assertEquals("Mz4DGzFLQysSGC98ESAnSafMLbxa71ls/zzUFOdCIJw9L0J8Q0Gt7+yCM+Ag73Tm5OTwpBemFOqPFiZ5BeBo4Q==",
            config.getAuth().getJwt().getKey(), "Incorrect auth/jwt/key");

    assertEquals("password", config.getAuth().getJwt().getKeyStorePassword(), "Wrong auth/jwt/keyStorePassword");
    assertEquals("/tmp/trellisData/keystore.jks", config.getAuth().getJwt().getKeyStore(), "Wrong keystore path!");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("baz"), "'baz' not in auth/jwt/keyIds");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("bar"), "'bar' not in auth/jwt/keyIds");
    assertTrue(config.getAuth().getJwt().getKeyIds().contains("trellis"), "'trellis' not in auth/jwt/keyIds");
    assertEquals(3, config.getAuth().getJwt().getKeyIds().size(), "Incorrect count of auth/jwt/keyIds");
    assertEquals("https://www.trellisldp.org/testing/jwks.json", config.getAuth().getJwt().getJwks(),
            "Wrong jwks value!");
}
 
Example #11
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwtAuthenticatorFederated() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setJwks(null);
    config.getAuth().getJwt().setKeyStore(resourceFilePath("keystore.jks"));
    config.getAuth().getJwt().setKeyIds(asList("trellis", "trellis-ec", "trellis-public"));
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof FederatedJwtAuthenticator,
            "JWT auth not enabled!");
}
 
Example #12
Source File: AbstractConfigurationTest.java    From dropwizard-pac4j with Apache License 2.0 5 votes vote down vote up
protected Pac4jFactory getPac4jFactory(
        Collection<Pac4jFeatureSupport> featuresSupported,
        String resourceName) throws Exception {
    ObjectMapper om = Jackson.newObjectMapper();
    Bootstrap<?> b = mock(Bootstrap.class);
    when(b.getObjectMapper()).thenReturn(om);

    for (Pac4jFeatureSupport fs : featuresSupported) {
        fs.setup(b);
    }

    return new YamlConfigurationFactory<>(Pac4jFactory.class,
            Validators.newValidator(), om, "dw").build(
                    new File(Resources.getResource(resourceName).toURI()));
}
 
Example #13
Source File: UpgradeCommand.java    From irontest with Apache License 2.0 5 votes vote down vote up
private IronTestConfiguration getIronTestConfiguration(String ironTestHome) throws IOException, ConfigurationException {
    Path configYmlFilePath = Paths.get(ironTestHome, "config.yml");
    ObjectMapper objectMapper = Jackson.newObjectMapper();
    Validator validator = Validators.newValidator();
    YamlConfigurationFactory<IronTestConfiguration> factory =
            new YamlConfigurationFactory<>(IronTestConfiguration.class, validator, objectMapper, "dw");
    IronTestConfiguration configuration = factory.build(configYmlFilePath.toFile());
    return configuration;
}
 
Example #14
Source File: Java8Bundle.java    From dropwizard-java8 with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(final Bootstrap<?> bootstrap) {
    bootstrap.getObjectMapper().registerModules(new Jdk8Module());
    bootstrap.getObjectMapper().registerModules(new JavaTimeModule());

    final ValidatorFactory validatorFactory = Validators.newConfiguration()
            .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
            .buildValidatorFactory();
    bootstrap.setValidatorFactory(validatorFactory);
}
 
Example #15
Source File: Cli.java    From oxd with Apache License 2.0 5 votes vote down vote up
private static OxdServerConfiguration parseConfiguration(String pathToYaml) throws IOException, ConfigurationException {
    if (StringUtils.isBlank(pathToYaml)) {
        System.out.println("Path to yml configuration file is not specified. Exit!");
        System.exit(1);
    }
    File file = new File(pathToYaml);
    if (!file.exists()) {
        System.out.println("Failed to find yml configuration file. Please check " + pathToYaml);
        System.exit(1);
    }

    DefaultConfigurationFactoryFactory<OxdServerConfiguration> configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>();
    ConfigurationFactory<OxdServerConfiguration> configurationFactory = configurationFactoryFactory.create(OxdServerConfiguration.class, Validators.newValidatorFactory().getValidator(), Jackson.newObjectMapper(), "dw");
    return configurationFactory.build(file);
}
 
Example #16
Source File: TestUtils.java    From oxd with Apache License 2.0 5 votes vote down vote up
public static OxdServerConfiguration parseConfiguration(String pathToYaml) throws IOException, ConfigurationException {

        File file = new File(pathToYaml);
        if (!file.exists()) {
            System.out.println("Failed to find yml configuration file. Please check " + pathToYaml);
            System.exit(1);
        }

        DefaultConfigurationFactoryFactory<OxdServerConfiguration> configurationFactoryFactory = new DefaultConfigurationFactoryFactory<>();
        ConfigurationFactory<OxdServerConfiguration> configurationFactory = configurationFactoryFactory.create(OxdServerConfiguration.class, Validators.newValidatorFactory().getValidator(), Jackson.newObjectMapper(), "dw");
        return configurationFactory.build(file);
    }
 
Example #17
Source File: InstancesTest.java    From breakerbox with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setupTest() throws Exception {
    PluginsFactory.setInstanceDiscovery(new YamlInstanceDiscovery(
            Paths.get(Resources.getResource("turbineConfigurations/instances.yml").toURI()),
            Validators.newValidator(),
            Jackson.newObjectMapper()));
}
 
Example #18
Source File: SyncComparatorTest.java    From breakerbox with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
    PluginsFactory.setInstanceDiscovery(new YamlInstanceDiscovery(
            Paths.get(Resources.getResource("turbineConfigurations/instances.yml").toURI()),
            Validators.newValidator(),
            Jackson.newObjectMapper()));
    mockFactory = mock(TenacityConfigurationFetcher.Factory.class);
    mockTenacityStory = mock(BreakerboxStore.class);
    mockFetcher = mock(TenacityConfigurationFetcher.class);
}
 
Example #19
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwtAuthenticatorNoKeystore() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    final String nonexistent = resourceFilePath("config1.yml").replaceAll("config1.yml", "nonexistent.yml");
    config.getAuth().getJwt().setJwks(null);
    config.getAuth().getJwt().setKeyStore(nonexistent);
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
            "JWT auth not disabled!");
}
 
Example #20
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwtAuthenticatorBadKeystore() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setJwks(null);
    config.getAuth().getJwt().setKeyStore(resourceFilePath("config1.yml"));
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
            "JWT auth not disabled!");
}
 
Example #21
Source File: ComplianceToolModeTest.java    From verify-service-provider with MIT License 5 votes vote down vote up
@Test
public void testThatConfigurationArgumentCanBeParsed() throws ArgumentParserException, JsonProcessingException {
    ComplianceToolMode complianceToolMode = new ComplianceToolMode(objectMapper, Validators.newValidator(), mock(VerifyServiceProviderApplication.class));

    final Subparser subparser = createParser();
    complianceToolMode.configure(subparser);

    String suppliedHost = "127.0.0.1";
    String suppliedCallbackUrl = HTTP_LOCALHOST_8080;
    int suppliedTimeout = 6;
    MatchingDataset suppliedMatchingDataset = new MatchingDatasetBuilder().build();

    int suppliedPort = 0;
    Namespace namespace = subparser.parseArgs(
            createArguments(
                    "--url", suppliedCallbackUrl,
                    "-d", objectMapper.writeValueAsString(suppliedMatchingDataset),
                    "--host", suppliedHost,
                    "-p", String.valueOf(suppliedPort),
                    "-t", String.valueOf(suppliedTimeout)
            )
    );

    MatchingDataset actual = namespace.get(ComplianceToolMode.IDENTITY_DATASET);
    assertThat(actual).isEqualToComparingFieldByFieldRecursively(suppliedMatchingDataset);

    String url = namespace.get(ComplianceToolMode.ASSERTION_CONSUMER_URL);
    assertThat(url).isEqualTo(suppliedCallbackUrl);

    Integer timeout = namespace.get(ComplianceToolMode.TIMEOUT);
    assertThat(timeout).isEqualTo(suppliedTimeout);

    Integer port = namespace.get(ComplianceToolMode.PORT);
    assertThat(port).isEqualTo(suppliedPort);

    String host = namespace.get(ComplianceToolMode.BIND_HOST);
    assertThat(host).isEqualTo(suppliedHost);

}
 
Example #22
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwtAuthenticatorNoKeyIds() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setJwks(null);
    config.getAuth().getJwt().setKeyStore(resourceFilePath("keystore.jks"));
    config.getAuth().getJwt().setKeyIds(asList("foo", "bar"));
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
            "JWT auth not disabled!");
}
 
Example #23
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwtAuthenticator() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    config.getAuth().getJwt().setJwks(null);
    config.getAuth().getJwt().setKeyStore(resourceFilePath("keystore.jks"));
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwtAuthenticator,
            "JWT auth not enabled!");
}
 
Example #24
Source File: TrellisUtilsTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testGetJwksAuthenticator() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    assertTrue(TrellisUtils.getJwtAuthenticator(config.getAuth().getJwt()) instanceof JwksAuthenticator,
            "JWT auth not enabled!");
}
 
Example #25
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationCORS1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getCors().getEnabled(), "CORS isn't enabled!");
    assertTrue(config.getCors().getAllowOrigin().contains("*"), "CORS origin not '*'");
    assertTrue(config.getCors().getAllowHeaders().contains("Link"), "Link not in CORS allow-headers!");
    assertTrue(config.getCors().getAllowMethods().contains("PATCH"), "PATCH not in CORS allow-methods!");
    assertTrue(config.getCors().getExposeHeaders().contains("Location"), "Location not in CORS expose-headers!");
    assertEquals(180, config.getCors().getMaxAge(), "incorrect max-age in CORS headers!");
    assertTrue(config.getCors().getAllowCredentials(), "CORS allow-credentials not set!");
}
 
Example #26
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationNamespaces1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("/tmp/trellisData/namespaces.json", config.getNamespaces(), "Incorrect namespace location!");
}
 
Example #27
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationLocations() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("/tmp/trellisData/binaries", config.getBinaries(), "Incorrect binary location!");
    assertEquals("/tmp/trellisData/mementos", config.getMementos(), "Incorrect memento location!");
    assertEquals("http://localhost:8080/", config.getBaseUrl(), "Incorrect base URL!");
    assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hub URL!");

    final String resources = "http://triplestore.example.com/";
    config.setResources(resources);
    assertEquals(resources, config.getResources(), "Incorrect resource location!");
}
 
Example #28
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationNotifications() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertFalse(config.getNotifications().getEnabled(), "Notifications aren't enabled!");
    assertEquals(NotificationsConfiguration.Type.NONE, config.getNotifications().getType(),
            "Incorrect notification type!");
    assertEquals("example.com:1234", config.getNotifications().getConnectionString(), "Incorrect connect string!");
    assertEquals("foo", config.getNotifications().any().get("some.other.value"), "Incorrect custom value!");
    assertEquals("test", config.getNotifications().getTopicName(), "Incorrect topic name!");
    assertEquals("true", config.getNotifications().any().get("use.queue"), "Incorrect custom value!");
}
 
Example #29
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationAssets1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));
    assertEquals("org/trellisldp/rdfa/resource.mustache", config.getAssets().getTemplate(), "Incorrect asset tpl!");
    assertEquals("http://example.org/image.icon", config.getAssets().getIcon(), "Incorrect asset icon!");
    assertTrue(config.getAssets().getJs().contains("http://example.org/scripts1.js"), "Incorrect asset js!");
    assertTrue(config.getAssets().getCss().contains("http://example.org/styles1.css"), "Incorrect asset css!");
}
 
Example #30
Source File: TrellisConfigurationTest.java    From trellis with Apache License 2.0 5 votes vote down vote up
@Test
void testConfigurationGeneral1() throws Exception {
    final AppConfiguration config = new YamlConfigurationFactory<>(AppConfiguration.class,
            Validators.newValidator(), Jackson.newMinimalObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("Trellis", config.getDefaultName(), "Incorrect default name!");
    assertEquals(86400, config.getCache().getMaxAge(), "Incorrect maxAge!");
    assertTrue(config.getCache().getMustRevalidate(), "Incorrect cache/mustRevalidate value!");
    assertFalse(config.getCache().getNoCache(), "Incorrect cache/noCache value!");
    assertEquals(10L, config.getJsonld().getCacheSize(), "Incorrect jsonld/cacheSize value!");
    assertEquals(48L, config.getJsonld().getCacheExpireHours(), "Incorrect jsonld/cacheExpireHours value!");
    assertFalse(config.getIsVersioningEnabled(), "Incorrect versioning value!");
    assertTrue(config.getJsonld().getContextDomainWhitelist().isEmpty(), "Incorrect jsonld/contextDomainWhitelist");
    assertTrue(config.getJsonld().getContextWhitelist().contains("http://example.org/context.json"),
            "Incorrect jsonld/contextWhitelist value!");
    assertNull(config.getResources(), "Unexpected resources value!");
    assertEquals("http://hub.example.com/", config.getHubUrl(), "Incorrect hub value!");
    assertEquals(2, config.getBinaryHierarchyLevels(), "Incorrect binaryHierarchyLevels value!");
    assertEquals(1, config.getBinaryHierarchyLength(), "Incorrect binaryHierarchyLength value!");
    assertEquals("my.cluster.node", config.any().get("cassandraAddress"), "Incorrect custom value!");
    assertEquals(245993, config.any().get("cassandraPort"), "Incorrect custom value (2)!");
    @SuppressWarnings("unchecked")
    final Map<String, Object> extraConfig = (Map<String, Object>) config.any().get("extraConfigValues");
    assertTrue((Boolean) extraConfig.get("one"), "Invalid nested custom values as boolean!");
    @SuppressWarnings("unchecked")
    final List<String> list = (List<String>) extraConfig.get("two");
    assertEquals(newArrayList("value1", "value2"), list, "Invalid nested custom values as list!");
}