james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [5/6] james-project git commit: JAMES-2043 UserProvisioningFilter should not try to update readOnly users repository
Date Tue, 06 Jun 2017 08:28:54 GMT
JAMES-2043 UserProvisioningFilter should not try to update readOnly users repository


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c05b38f3
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c05b38f3
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c05b38f3

Branch: refs/heads/master
Commit: c05b38f3eaf2db75ad0963fd99f3bfaa31400125
Parents: 8e9d7be
Author: benwa <btellier@linagora.com>
Authored: Fri Jun 2 11:57:38 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Jun 6 15:27:57 2017 +0700

----------------------------------------------------------------------
 .../james/jmap/UserProvisioningFilter.java      |  6 ++--
 .../james/jmap/UserProvisioningFilterTest.java  | 35 ++++++++++++++++++++
 2 files changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/c05b38f3/server/protocols/jmap/src/main/java/org/apache/james/jmap/UserProvisioningFilter.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UserProvisioningFilter.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UserProvisioningFilter.java
index 95425d4..04bee42 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UserProvisioningFilter.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UserProvisioningFilter.java
@@ -62,8 +62,10 @@ public class UserProvisioningFilter implements Filter {
     
     @Override
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
-        Optional<MailboxSession> session = Optional.ofNullable((MailboxSession)request.getAttribute(AuthenticationFilter.MAILBOX_SESSION));
-        session.ifPresent(this::createAccountIfNeeded);
+        if (!usersRepository.isReadOnly()) {
+            Optional<MailboxSession> session = Optional.ofNullable((MailboxSession)
request.getAttribute(AuthenticationFilter.MAILBOX_SESSION));
+            session.ifPresent(this::createAccountIfNeeded);
+        }
         chain.doFilter(request, response);
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/c05b38f3/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterTest.java
index 4bab49d..dde8aa5 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/UserProvisioningFilterTest.java
@@ -19,8 +19,11 @@
 package org.apache.james.jmap;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
 import java.io.IOException;
@@ -33,6 +36,7 @@ import javax.servlet.http.HttpServletResponse;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.metrics.api.NoopMetricFactory;
+import org.apache.james.user.api.UsersRepository;
 import org.apache.james.user.api.UsersRepositoryException;
 import org.apache.james.user.lib.mock.InMemoryUsersRepository;
 import org.junit.Before;
@@ -90,4 +94,35 @@ public class UserProvisioningFilterTest {
         verify(chain).doFilter(request, response);
         assertThat(usersRepository.list()).contains(USERNAME);
     }
+
+    @Test
+    public void filterShouldNotTryToAddUserWhenReadOnlyUsersRepository() throws Exception
{
+        UsersRepository usersRepository = mock(UsersRepository.class);
+        when(usersRepository.isReadOnly()).thenReturn(true);
+        sut = new UserProvisioningFilter(usersRepository, new NoopMetricFactory());
+
+        MailboxSession mailboxSession = new MockMailboxSession(MAIL);
+        when(request.getAttribute(AuthenticationFilter.MAILBOX_SESSION))
+            .thenReturn(mailboxSession);
+
+        sut.doFilter(request, response, chain);
+
+        verify(usersRepository).isReadOnly();
+        verifyNoMoreInteractions(usersRepository);
+    }
+
+    @Test
+    public void filterShouldChainCallsWhenReadOnlyUsersRepository() throws Exception {
+        UsersRepository usersRepository = mock(UsersRepository.class);
+        when(usersRepository.isReadOnly()).thenReturn(true);
+        sut = new UserProvisioningFilter(usersRepository, new NoopMetricFactory());
+
+        MailboxSession mailboxSession = new MockMailboxSession(MAIL);
+        when(request.getAttribute(AuthenticationFilter.MAILBOX_SESSION))
+            .thenReturn(mailboxSession);
+
+        sut.doFilter(request, response, chain);
+
+        verify(chain).doFilter(eq(request), any());
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message