Project

General

Profile

Download (2.36 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.vaadin.presenter;
10

    
11
import java.net.URI;
12
import java.net.URISyntaxException;
13

    
14
import org.apache.log4j.Logger;
15
import org.junit.Assert;
16
import org.junit.BeforeClass;
17
import org.junit.Test;
18
import org.springframework.security.authentication.BadCredentialsException;
19

    
20
import com.vaadin.server.VaadinSession;
21

    
22
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
23
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinAuthentication;
24
import eu.etaxonomy.cdm.vaadin.view.AuthenticationPresenter;
25

    
26
/**
27
 * @author cmathew
28
 * @date 28 Apr 2015
29
 *
30
 */
31
public class AuthenticationPresenterTest extends CdmVaadinBaseTest {
32

    
33
    private static final Logger logger = Logger.getLogger(AuthenticationPresenterTest.class);
34

    
35
    private static AuthenticationPresenter ap;
36

    
37
    @BeforeClass
38
    public static void init() {
39
        ap = new AuthenticationPresenter();
40
    }
41

    
42
    @Test
43
    public void testLogin() throws URISyntaxException {
44
        URI uri = new URI("http://localhost:8080/cdm-vaadin/app/authtest");
45
        String context = "/cdm-vaadin";
46
        boolean isAuthenticated = false;
47
        try {
48
            isAuthenticated = ap.login(uri, context, "admin", "000");
49
            Assert.fail("BadCredentialsException should be thrown here");
50
        } catch(BadCredentialsException e){
51

    
52
        }
53

    
54
        isAuthenticated = ap.login(uri, context, "admin", "00000");
55
        Assert.assertTrue(isAuthenticated);
56

    
57
        CdmVaadinAuthentication authentication = (CdmVaadinAuthentication) VaadinSession.getCurrent().getAttribute(CdmVaadinAuthentication.KEY);
58
        Assert.assertTrue(authentication.isAuthenticated(uri, context));
59

    
60
        URI anotherUri = new URI("http://localhost:8081/cdm-edit/app/authtest");
61
        Assert.assertFalse(authentication.isAuthenticated(anotherUri, context));
62

    
63
        String anotherContext = "/cdm-edit";
64
        Assert.assertFalse(authentication.isAuthenticated(uri, anotherContext));
65

    
66
        isAuthenticated = ap.login(anotherUri, anotherContext, "admin", "00000");
67
        Assert.assertTrue(isAuthenticated);
68

    
69
        Assert.assertTrue(authentication.isAuthenticated(anotherUri, anotherContext));
70

    
71
    }
72

    
73
}
(1-1/5)