blob: afef6b238a9c9afa64a253342a01241aede4d010 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/*******************************************************************************
* Copyright (c) 2013 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.authentication.admin.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.MockitoAnnotations.initMocks;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.osee.authentication.admin.AuthenticatedUser;
import org.eclipse.osee.authentication.admin.AuthenticationConstants;
import org.eclipse.osee.authentication.admin.AuthenticationRequest;
import org.eclipse.osee.authentication.admin.AuthenticationRequestBuilder;
import org.eclipse.osee.logger.Log;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
/**
* Test Case for {@link NoneAuthenticationProvider}
*
* @author Roberto E. Escobar
*/
public class NoneAuthenticationProviderTest {
private static final String NONE_SCHEME = "none";
private static final String USERNAME = "my username";
private static final String PASSWORD = "my password";
// @formatter:off
@Mock private Log logger;
// @formatter:on
private AuthenticationAdminImpl admin;
@Before
public void testSetup() {
initMocks(this);
admin = new AuthenticationAdminImpl();
admin.setLogger(logger);
NoneAuthenticationProvider provider = new NoneAuthenticationProvider();
admin.addAuthenticationProvider(provider);
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(AuthenticationConstants.AUTHENTICATION_SCHEME_ALLOWED,
NoneAuthenticationProvider.AUTHENTICATION_TYPE);
admin.start(properties);
}
@Test
public void testAuthenticate() {
Iterable<String> iterable = admin.getAllowedSchemes();
assertEquals(NONE_SCHEME, iterable.iterator().next());
AuthenticationRequest request = AuthenticationRequestBuilder.newBuilder()//
.scheme(NONE_SCHEME) //
.userName(USERNAME)//
.password(PASSWORD)//
.build();
AuthenticatedUser actual = admin.authenticate(request);
assertNotNull(actual);
assertEquals(USERNAME, actual.getName());
assertEquals(USERNAME, actual.getUserName());
assertEquals(USERNAME, actual.getDisplayName());
assertEquals("", actual.getEmailAddress());
assertEquals(false, actual.getRoles().iterator().hasNext());
assertEquals(true, actual.isActive());
assertEquals(true, actual.isAuthenticated());
}
}
|