Search in sources :

Example 66 with Configuration

use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.

the class HTTPAlarmCallbackTest method checkConfigurationFailsWithMissingURL.

@Test
public void checkConfigurationFailsWithMissingURL() throws Exception {
    final Map<String, Object> configMap = ImmutableMap.of();
    final Configuration configuration = new Configuration(configMap);
    alarmCallback.initialize(configuration);
    expectedException.expect(ConfigurationException.class);
    expectedException.expectMessage("URL parameter is missing.");
    alarmCallback.checkConfiguration();
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) Test(org.junit.Test)

Example 67 with Configuration

use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.

the class GelfCodecTest method decodeLargeCompressedMessageFails.

@Test
public void decodeLargeCompressedMessageFails() throws Exception {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("JSON is null/could not be parsed (invalid JSON)");
    expectedException.expectCause(isA(JsonParseException.class));
    final Configuration configuration = new Configuration(Collections.singletonMap("decompress_size_limit", 100));
    final GelfCodec codec = new GelfCodec(configuration, aggregator);
    final String json = "{" + "\"version\": \"1.1\"," + "\"host\": \"example.org\"," + "\"short_message\": \"A short message that helps you identify what is going on\"," + "\"full_message\": \"Backtrace here\\n\\nMore stuff\"," + "\"timestamp\": 1385053862.3072," + "\"level\": 1," + "\"_some_bytes1\": \"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, \"," + "\"_some_bytes2\": \"sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, \"," + "\"_some_bytes2\": \"sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.\"" + "}";
    final byte[] payload = TestHelper.zlibCompress(json);
    assumeTrue(payload.length > 100);
    final RawMessage rawMessage = new RawMessage(payload);
    codec.decode(rawMessage);
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) JsonParseException(com.fasterxml.jackson.core.JsonParseException) RawMessage(org.graylog2.plugin.journal.RawMessage) Test(org.junit.Test)

Example 68 with Configuration

use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.

the class SyslogCodecTest method testDecodeStructuredIssue845WithExpandStructuredData.

@Test
public void testDecodeStructuredIssue845WithExpandStructuredData() throws Exception {
    when(configuration.getBoolean(SyslogCodec.CK_EXPAND_STRUCTURED_DATA)).thenReturn(true);
    final SyslogCodec codec = new SyslogCodec(configuration, metricRegistry);
    final Message message = codec.decode(buildRawMessage(STRUCTURED_ISSUE_845));
    assertNotNull(message);
    assertEquals(message.getMessage(), "User page 13 requested");
    assertEquals(((DateTime) message.getField("timestamp")).withZone(DateTimeZone.UTC), new DateTime("2015-01-06T20:56:33.287Z", DateTimeZone.UTC));
    assertEquals(message.getField("source"), "app-1");
    assertEquals(message.getField("level"), 6);
    assertEquals(message.getField("facility"), "local7");
    assertEquals(message.getField("mdc@18060_ip"), "::ffff:132.123.15.30");
    assertEquals(message.getField("mdc@18060_logger"), "{c.corp.Handler}");
    assertEquals(message.getField("mdc@18060_session"), "4ot7");
    assertEquals(message.getField("mdc@18060_user"), "user@example.com");
    assertEquals(message.getField("mdc@18060_user-agent"), "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.2.5 (KHTML, like Gecko) Version/7.1.2 Safari/537.85.11");
    assertEquals(message.getField("application_name"), "app");
}
Also used : RawMessage(org.graylog2.plugin.journal.RawMessage) Message(org.graylog2.plugin.Message) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 69 with Configuration

use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.

the class UserServiceImplTest method testGetPermissionsForUser.

@Test
public void testGetPermissionsForUser() throws Exception {
    final InMemoryRolePermissionResolver permissionResolver = mock(InMemoryRolePermissionResolver.class);
    final UserService userService = new UserServiceImpl(mongoConnection, configuration, roleService, userFactory, permissionResolver);
    final UserImplFactory factory = new UserImplFactory(new Configuration());
    final UserImpl user = factory.create(new HashMap<>());
    user.setName("user");
    final Role role = createRole("Foo");
    user.setRoleIds(Collections.singleton(role.getId()));
    user.setPermissions(Collections.singletonList("hello:world"));
    when(permissionResolver.resolveStringPermission(role.getId())).thenReturn(Collections.singleton("foo:bar"));
    assertThat(userService.getPermissionsForUser(user)).containsOnly("users:passwordchange:user", "users:edit:user", "foo:bar", "hello:world");
}
Also used : Role(org.graylog2.shared.users.Role) Configuration(org.graylog2.Configuration) UserService(org.graylog2.shared.users.UserService) InMemoryRolePermissionResolver(org.graylog2.security.InMemoryRolePermissionResolver) Test(org.junit.Test)

Example 70 with Configuration

use of org.graylog2.plugin.configuration.Configuration in project graylog2-server by Graylog2.

the class UserServiceImplTest method testGetRoleNames.

@Test
public void testGetRoleNames() throws Exception {
    final UserImplFactory factory = new UserImplFactory(new Configuration());
    final UserImpl user = factory.create(new HashMap<>());
    final Role role = createRole("Foo");
    final ImmutableMap<String, Role> map = ImmutableMap.<String, Role>builder().put(role.getId(), role).build();
    when(roleService.loadAllIdMap()).thenReturn(map);
    assertThat(userService.getRoleNames(user)).isEmpty();
    user.setRoleIds(Sets.newHashSet(role.getId()));
    assertThat(userService.getRoleNames(user)).containsOnly("Foo");
    when(roleService.loadAllIdMap()).thenReturn(new HashMap<>());
    assertThat(userService.getRoleNames(user)).isEmpty();
}
Also used : Role(org.graylog2.shared.users.Role) Configuration(org.graylog2.Configuration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)34 Configuration (org.graylog2.plugin.configuration.Configuration)29 ApiOperation (io.swagger.annotations.ApiOperation)24 Timed (com.codahale.metrics.annotation.Timed)23 BadRequestException (javax.ws.rs.BadRequestException)19 Path (javax.ws.rs.Path)18 AuditEvent (org.graylog2.audit.jersey.AuditEvent)17 Consumes (javax.ws.rs.Consumes)13 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)13 MessageInput (org.graylog2.plugin.inputs.MessageInput)13 Stream (org.graylog2.plugin.streams.Stream)13 ApiResponses (io.swagger.annotations.ApiResponses)12 PUT (javax.ws.rs.PUT)11 ValidationException (org.graylog2.plugin.database.ValidationException)11 DateTime (org.joda.time.DateTime)11 Produces (javax.ws.rs.Produces)10 Configuration (org.graylog2.Configuration)10 POST (javax.ws.rs.POST)9 EmailConfiguration (org.graylog2.configuration.EmailConfiguration)9 URI (java.net.URI)8