Search in sources :

Example 91 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class LdapUserAuthenticatorTest method testSyncFromLdapEntryExistingUser.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testSyncFromLdapEntryExistingUser() {
    final LdapUserAuthenticator authenticator = spy(new LdapUserAuthenticator(ldapConnector, ldapSettingsService, userService, mock(RoleService.class), DateTimeZone.UTC));
    final LdapEntry userEntry = new LdapEntry();
    final LdapSettings ldapSettings = mock(LdapSettings.class);
    when(ldapSettings.getDisplayNameAttribute()).thenReturn("displayName");
    when(ldapSettings.getDefaultGroupId()).thenReturn("54e3deadbeefdeadbeef0001");
    when(ldapSettings.getAdditionalDefaultGroupIds()).thenReturn(Collections.emptySet());
    final HashMap<String, Object> fields = Maps.newHashMap();
    fields.put("permissions", Collections.singletonList("test:permission:1234"));
    when(userService.load(anyString())).thenReturn(new UserImpl(null, new Permissions(Collections.emptySet()), fields));
    final User ldapUser = authenticator.syncFromLdapEntry(userEntry, ldapSettings, "user");
    assertThat(ldapUser).isNotNull();
    assertThat(ldapUser.getPermissions()).contains("test:permission:1234");
    assertThat(ldapUser.isExternalUser()).isTrue();
    assertThat(ldapUser.getName()).isEqualTo("user");
    assertThat(ldapUser.getEmail()).isEqualTo("user@localhost");
    assertThat(ldapUser.getHashedPassword()).isEqualTo("User synced from LDAP.");
    assertThat(ldapUser.getTimeZone()).isEqualTo(DateTimeZone.UTC);
    assertThat(ldapUser.getRoleIds()).containsOnly("54e3deadbeefdeadbeef0001");
    assertThat(ldapUser.getPermissions()).isNotEmpty();
}
Also used : User(org.graylog2.plugin.database.users.User) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) LdapEntry(org.graylog2.shared.security.ldap.LdapEntry) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LdapSettings(org.graylog2.shared.security.ldap.LdapSettings) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 92 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class LdapUserAuthenticatorTest method testSyncFromLdapEntry.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testSyncFromLdapEntry() {
    final LdapUserAuthenticator authenticator = spy(new LdapUserAuthenticator(ldapConnector, ldapSettingsService, userService, mock(RoleService.class), DateTimeZone.UTC));
    final LdapEntry userEntry = new LdapEntry();
    final LdapSettings ldapSettings = mock(LdapSettings.class);
    when(ldapSettings.getDisplayNameAttribute()).thenReturn("displayName");
    when(ldapSettings.getDefaultGroupId()).thenReturn("54e3deadbeefdeadbeef0001");
    when(ldapSettings.getAdditionalDefaultGroupIds()).thenReturn(Collections.emptySet());
    when(userService.create()).thenReturn(new UserImpl(null, new Permissions(Collections.emptySet()), Maps.newHashMap()));
    final User ldapUser = authenticator.syncFromLdapEntry(userEntry, ldapSettings, "user");
    assertThat(ldapUser).isNotNull();
    assertThat(ldapUser.isExternalUser()).isTrue();
    assertThat(ldapUser.getName()).isEqualTo("user");
    assertThat(ldapUser.getEmail()).isEqualTo("user@localhost");
    assertThat(ldapUser.getHashedPassword()).isEqualTo("User synced from LDAP.");
    assertThat(ldapUser.getTimeZone()).isEqualTo(DateTimeZone.UTC);
    assertThat(ldapUser.getRoleIds()).containsOnly("54e3deadbeefdeadbeef0001");
    assertThat(ldapUser.getPermissions()).isNotEmpty();
}
Also used : User(org.graylog2.plugin.database.users.User) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) LdapEntry(org.graylog2.shared.security.ldap.LdapEntry) LdapSettings(org.graylog2.shared.security.ldap.LdapSettings) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 93 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class SavedSearchServiceImplTest method testCreate.

@Test
@UsingDataSet(loadStrategy = LoadStrategyEnum.DELETE_ALL)
public void testCreate() throws Exception {
    final String title = "Example Title";
    final Map<String, Object> query = Collections.emptyMap();
    final String creatorUserId = "someuser";
    final DateTime createdAt = Tools.nowUTC();
    final SavedSearch savedSearch = savedSearchService.create(title, query, creatorUserId, createdAt);
    assertNotNull("Should have returned a SavedSearch", savedSearch);
    assertEquals("Collection should still be empty", 0, savedSearchService.all().size());
}
Also used : DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Example 94 with UsingDataSet

use of com.lordofthejars.nosqlunit.annotation.UsingDataSet in project graylog2-server by Graylog2.

the class AccessTokenServiceImplTest method testTouch.

@Test
@UsingDataSet(locations = "accessTokensSingleToken.json", loadStrategy = LoadStrategyEnum.CLEAN_INSERT)
public void testTouch() throws Exception {
    final AccessToken token = accessTokenService.load("foobar");
    final DateTime initialLastAccess = token.getLastAccess();
    accessTokenService.touch(token);
    assertThat(token.getLastAccess()).isAfter(initialLastAccess);
}
Also used : DateTime(org.joda.time.DateTime) UsingDataSet(com.lordofthejars.nosqlunit.annotation.UsingDataSet) Test(org.junit.Test)

Aggregations

UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)94 Test (org.junit.Test)94 DateTime (org.joda.time.DateTime)40 DBCollection (com.mongodb.DBCollection)29 ZonedDateTime (java.time.ZonedDateTime)19 DBObject (com.mongodb.DBObject)15 BasicDBObjectBuilder (com.mongodb.BasicDBObjectBuilder)13 ObjectId (org.bson.types.ObjectId)9 MongoDBServiceTest (org.graylog2.database.MongoDBServiceTest)9 Timer (com.codahale.metrics.Timer)6 Histogram (com.codahale.metrics.Histogram)5 JsonPath (com.jayway.restassured.path.json.JsonPath)5 ValidatableResponse (com.jayway.restassured.response.ValidatableResponse)5 HistogramResult (org.graylog2.indexer.results.HistogramResult)5 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)5 List (java.util.List)4 TermsResult (org.graylog2.indexer.results.TermsResult)4 User (org.graylog2.plugin.database.users.User)4 LdapSettings (org.graylog2.shared.security.ldap.LdapSettings)4 Map (java.util.Map)3