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();
}
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);
}
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");
}
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");
}
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();
}
Aggregations