2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.authprovider;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.doThrow;
15 import static org.mockito.Mockito.mock;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.junit.MockitoJUnitRunner;
21 import org.opendaylight.aaa.api.AuthenticationException;
22 import org.opendaylight.aaa.api.Claim;
23 import org.opendaylight.aaa.api.PasswordCredentialAuth;
24 import org.opendaylight.aaa.api.PasswordCredentials;
25 import org.opendaylight.netconf.auth.aaa.CredentialServiceAuthProvider;
27 @RunWith(MockitoJUnitRunner.StrictStubs.class)
28 public class CredentialServiceAuthProviderTest {
30 private PasswordCredentialAuth credAuth;
33 public void testAuthenticatedTrue() throws Exception {
34 Claim claim = mock(Claim.class);
35 doReturn("domain").when(claim).domain();
36 doReturn(claim).when(credAuth).authenticate(any(PasswordCredentials.class));
38 CredentialServiceAuthProvider credentialServiceAuthProvider = new CredentialServiceAuthProvider(credAuth);
39 assertTrue(credentialServiceAuthProvider.authenticated("user", "pwd"));
43 public void testAuthenticatedFalse() throws Exception {
44 doThrow(AuthenticationException.class).when(credAuth).authenticate(any(PasswordCredentials.class));
45 CredentialServiceAuthProvider credentialServiceAuthProvider = new CredentialServiceAuthProvider(credAuth);
46 assertFalse(credentialServiceAuthProvider.authenticated("user", "pwd"));