示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailOnReadingInvalidEntries() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailOnReadingInvalidEntries()
        {
            // Given
            AssertableLogProvider logProvider = new AssertableLogProvider();

            _fs.mkdir(_authFile.ParentFile);
            // First line is correctly formatted, second line has an extra field
            FileRepositorySerializer.WriteToFile(_fs, _authFile, UTF8.encode("admin:SHA-256,A42E541F276CF17036DB7818F8B09B1C229AAD52A17F69F4029617F3A554640F,FB7E8AE08A6A7C741F678AD22217808F:\n" + "neo4j:fc4c600b43ffe4d5857b4439c35df88f:SHA-256," + "A42E541F276CF17036DB7818F8B09B1C229AAD52A17F69F4029617F3A554640F,FB7E8AE08A6A7C741F678AD22217808F:\n"));

            // When
            FileUserRepository users = new FileUserRepository(_fs, _authFile, logProvider);

            Thrown.expect(typeof(System.InvalidOperationException));
            Thrown.expectMessage(startsWith("Failed to read authentication file: "));

            try
            {
                users.Start();
            }
            // Then
            catch (System.InvalidOperationException e)
            {
                assertThat(users.NumberOfUsers(), equalTo(0));
                logProvider.AssertExactly(AssertableLogProvider.inLog(typeof(FileUserRepository)).error("Failed to read authentication file \"%s\" (%s)", _authFile.AbsolutePath, "wrong number of line fields, expected 3, got 4 [line 2]"));
                throw e;
            }
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverIfCrashedDuringMove() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverIfCrashedDuringMove()
        {
            // Given
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.IOException exception = new java.io.IOException("simulated IO Exception on create");
            IOException           exception          = new IOException("simulated IO Exception on create");
            FileSystemAbstraction crashingFileSystem = new DelegatingFileSystemAbstractionAnonymousInnerClass(this, _fs, exception);

            FileUserRepository users = new FileUserRepository(crashingFileSystem, _authFile, _logProvider);

            users.Start();
            User user = (new User.Builder("jake", LegacyCredential.Inaccessible)).withRequiredPasswordChange(true).build();

            // When
            try
            {
                users.Create(user);
                fail("Expected an IOException");
            }
            catch (IOException e)
            {
                assertSame(exception, e);
            }

            // Then
            assertFalse(crashingFileSystem.FileExists(_authFile));
            assertThat(crashingFileSystem.ListFiles(_authFile.ParentFile).Length, equalTo(0));
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAddInitialUserIfUsersExist() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAddInitialUserIfUsersExist()
        {
            // Given
            FileUserRepository initialUserRepository = CommunitySecurityModule.GetInitialUserRepository(Config, NullLogProvider.Instance, FsRule.get());

            initialUserRepository.Start();
            initialUserRepository.Create(NewUser("initUser", "123", false));
            initialUserRepository.Shutdown();
            Users.start();
            Users.create(NewUser("oldUser", "321", false));
            Users.shutdown();

            // When
            AuthManager().start();

            // Then
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.security.User initUser = users.getUserByName("initUser");
            User initUser = Users.getUserByName("initUser");

            assertNull(initUser);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.security.User oldUser = users.getUserByName("oldUser");
            User oldUser = Users.getUserByName("oldUser");

            assertNotNull(oldUser);
            assertTrue(oldUser.Credentials().matchesPassword("321"));
            assertFalse(oldUser.PasswordChangeRequired());
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStoreAndRetrieveUsersByName() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldStoreAndRetrieveUsersByName()
        {
            // Given
            FileUserRepository users = new FileUserRepository(_fs, _authFile, _logProvider);
            User user = (new User.Builder("jake", LegacyCredential.Inaccessible)).withRequiredPasswordChange(true).build();

            users.Create(user);

            // When
            User result = users.GetUserByName(user.Name());

            // Then
            assertThat(result, equalTo(user));
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotFindUserAfterDelete() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotFindUserAfterDelete()
        {
            // Given
            FileUserRepository users = new FileUserRepository(_fs, _authFile, _logProvider);
            User user = (new User.Builder("jake", LegacyCredential.Inaccessible)).withRequiredPasswordChange(true).build();

            users.Create(user);

            // When
            users.Delete(user);

            // Then
            assertThat(users.GetUserByName(user.Name()), nullValue());
        }
示例#6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAllowComplexNames() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotAllowComplexNames()
        {
            // Given
            FileUserRepository users = new FileUserRepository(_fs, _authFile, _logProvider);

            // When
            users.AssertValidUsername("neo4j");
            users.AssertValidUsername("johnosbourne");
            users.AssertValidUsername("john_osbourne");

            assertException(() => users.assertValidUsername(null), typeof(InvalidArgumentsException), "The provided username is empty.");
            assertException(() => users.assertValidUsername(""), typeof(InvalidArgumentsException), "The provided username is empty.");
            assertException(() => users.assertValidUsername(","), typeof(InvalidArgumentsException), "Username ',' contains illegal characters. Use ascii characters that are not ',', ':' or whitespaces" + ".");
            assertException(() => users.assertValidUsername("with space"), typeof(InvalidArgumentsException), "Username 'with space' contains illegal characters. Use ascii characters that are not ',', ':' or " + "whitespaces.");
            assertException(() => users.assertValidUsername("with:colon"), typeof(InvalidArgumentsException), "Username 'with:colon' contains illegal characters. Use ascii characters that are not ',', ':' or " + "whitespaces.");
            assertException(() => users.assertValidUsername("withå"), typeof(InvalidArgumentsException), "Username 'withå' contains illegal characters. Use ascii characters that are not ',', ':' or " + "whitespaces.");
        }
示例#7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowIfExistingUserDoesNotMatch() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowIfExistingUserDoesNotMatch()
        {
            // Given
            FileUserRepository users = new FileUserRepository(_fs, _authFile, _logProvider);
            User user = (new User.Builder("jake", LegacyCredential.Inaccessible)).withRequiredPasswordChange(true).build();

            users.Create(user);
            User modifiedUser = user.Augment().withCredentials(LegacyCredential.ForPassword("foo")).build();

            // When
            User updatedUser = user.Augment().withCredentials(LegacyCredential.ForPassword("bar")).build();

            try
            {
                users.Update(modifiedUser, updatedUser);
                fail("expected exception not thrown");
            }
            catch (ConcurrentModificationException)
            {
                // Then continue
            }
        }
示例#8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLoadInitialUserIfNoneExistEvenWithSamePassword() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLoadInitialUserIfNoneExistEvenWithSamePassword()
        {
            // Given
            FileUserRepository initialUserRepository = CommunitySecurityModule.GetInitialUserRepository(Config, NullLogProvider.Instance, FsRule.get());

            initialUserRepository.Start();
            initialUserRepository.create(new User.Builder("neo4j", LegacyCredential.ForPassword("neo4j"))
                                         .withRequiredPasswordChange(false).build());
            initialUserRepository.Shutdown();

            // When
            AuthManager().start();

            // Then
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.security.User user = users.getUserByName("neo4j");
            User user = Users.getUserByName("neo4j");

            assertNotNull(user);
            assertTrue(user.Credentials().matchesPassword("neo4j"));
            assertFalse(user.PasswordChangeRequired());
        }
示例#9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvideUserByUsernameEvenIfMidSetUsers() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProvideUserByUsernameEvenIfMidSetUsers()
        {
            // Given
            FileUserRepository users = new FileUserRepository(_fs, _authFile, _logProvider);

            users.Create((new User.Builder("oskar", LegacyCredential.ForPassword("hidden"))).build());
            DoubleLatch latch = new DoubleLatch(2);

            // When
            Future <object> setUsers = Threading.execute(o =>
            {
                users.Users = new HangingListSnapshot(this, latch, 10L, java.util.Collections.emptyList());
                return(null);
            }, null);

            latch.StartAndWaitForAllToStart();

            // Then
            assertNotNull(users.GetUserByName("oskar"));

            latch.Finish();
            setUsers.get();
        }
示例#10
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowIfUpdateChangesName() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowIfUpdateChangesName()
        {
            // Given
            FileUserRepository users = new FileUserRepository(_fs, _authFile, _logProvider);
            User user = (new User.Builder("jake", LegacyCredential.Inaccessible)).withRequiredPasswordChange(true).build();

            users.Create(user);

            // When
            User updatedUser = (new User.Builder("john", LegacyCredential.Inaccessible)).withRequiredPasswordChange(true).build();

            try
            {
                users.Update(user, updatedUser);
                fail("expected exception not thrown");
            }
            catch (System.ArgumentException)
            {
                // Then continue
            }

            assertThat(users.GetUserByName(user.Name()), equalTo(user));
        }