@@ -0,0 +1,2156 @@
+package net.davidvoid.thor.lightning.service;%0A%0Aimport net.davidvoid.thor.lightning.config.RootConfig;%0Aimport net.davidvoid.thor.lightning.data.access.UserStore;%0Aimport net.davidvoid.thor.lightning.data.source.MongoDataSource;%0Aimport net.davidvoid.thor.lightning.entity.User;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.test.context.ActiveProfiles;%0Aimport org.springframework.test.context.ContextConfiguration;%0Aimport org.springframework.test.context.junit4.SpringJUnit4ClassRunner;%0A%0Aimport java.math.BigInteger;%0Aimport java.security.MessageDigest;%0Aimport java.security.NoSuchAlgorithmException;%0A%0Aimport static org.junit.Assert.*;%0A%0A/**%0A * Created by david on 5/5/16.%0A */%0A@RunWith(SpringJUnit4ClassRunner.class)%0A@ActiveProfiles(%22test%22)%0A@ContextConfiguration(classes = %7B RootConfig.class %7D)%0Apublic class AuthTest %7B%0A%0A    @Autowired%0A    UserStore store = null;%0A    @Autowired%0A    MongoDataSource source = null;%0A    @Autowired%0A    Auth auth = null;%0A%0A    @Before%0A    public void setup() %7B%0A        source.getDatabase().drop();%0A%0A        User user = new User();%0A        user.setName(%22david%22);%0A        user.setPassword(%22123%22);%0A        store.add(user);%0A    %7D%0A%0A%0A    @Test%0A    public void authenticate_WhenHasUserAndPasswordRight_WillSuccess() throws Exception %7B%0A        User user = auth.authenticate(%22david%22, %22123%22);%0A        assertNotNull(user);%0A        assertEquals(%22david%22, user.getName());%0A        assertEquals(%22123%22, shaDigest(user.getPassword()));%0A    %7D%0A%0A    @Test%0A    public void testUpdate() throws Exception %7B%0A%0A    %7D%0A%0A    @Test%0A    public void testRegister() throws Exception %7B%0A%0A    %7D%0A%0A    @Test%0A    public void testGetUser() throws Exception %7B%0A%0A    %7D%0A%0A    private String shaDigest(String password) %7B%0A        try %7B%0A            MessageDigest md = MessageDigest.getInstance(%22SHA-256%22);%0A            md.update(password.getBytes());%0A%0A            return String.format(%22%25064x%22,  new BigInteger(1, md.digest()));%0A        %7D catch (NoSuchAlgorithmException e) %7B%0A            throw new RuntimeException(%22SHA-256 not supported%22);%0A        %7D%0A    %7D%0A%7D

add auth test