1 package com.atlassian.user.impl.memory.security.authentication;
2
3 import com.atlassian.user.EntityException;
4 import com.atlassian.user.User;
5 import com.atlassian.user.generic.AbstractSpringTest;
6 import com.atlassian.user.impl.memory.MemoryUserManager;
7 import com.atlassian.user.security.authentication.Authenticator;
8
9 public class TestDefaultMemoryAuthenticator extends AbstractSpringTest
10 {
11 protected MemoryUserManager memoryUserManager;
12 protected Authenticator authenticator;
13
14 protected String[] getConfigLocations()
15 {
16 return new String[]{
17 "classpath:com/atlassian/user/impl/memory/memoryTestContext.xml",
18 };
19 }
20
21 protected void onTearDown() throws Exception
22 {
23 setDirty();
24 super.onTearDown();
25 }
26
27 public void setMemoryUserManager(MemoryUserManager memoryUserManager)
28 {
29 this.memoryUserManager = memoryUserManager;
30 }
31
32 public void setAuthenticator(Authenticator authenticator)
33 {
34 this.authenticator = authenticator;
35 }
36
37 public void testAuthenticate() throws EntityException
38 {
39 User user = memoryUserManager.createUser("test");
40 memoryUserManager.alterPassword(user, "testPassword");
41
42 assertTrue(authenticator.authenticate("test", "testPassword"));
43 }
44
45 public void testNullPassword() throws Exception
46 {
47 memoryUserManager.createUser("test");
48 assertFalse(authenticator.authenticate("test", "anypassword"));
49 }
50 }