2 * Copyright (c) 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
9 package org.opendaylight.aaa.idm.persistence;
11 import java.util.ArrayList;
12 import java.util.LinkedList;
13 import java.util.List;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mockito;
18 import org.opendaylight.aaa.api.IDMStoreException;
19 import org.opendaylight.aaa.api.IIDMStore;
20 import org.opendaylight.aaa.api.PasswordCredentials;
21 import org.opendaylight.aaa.api.SHA256Calculator;
22 import org.opendaylight.aaa.api.model.Domain;
23 import org.opendaylight.aaa.api.model.Grant;
24 import org.opendaylight.aaa.api.model.Grants;
25 import org.opendaylight.aaa.api.model.Role;
26 import org.opendaylight.aaa.api.model.User;
27 import org.opendaylight.aaa.api.model.Users;
28 import org.opendaylight.aaa.idm.IdmLightProxy;
29 import org.opendaylight.yang.gen.v1.config.aaa.authn.idmlight.rev151204.AAAIDMLightModule;
32 * @Author - Sharon Aicler (saichler@cisco.com)
34 public class PasswordHashTest {
37 public void before() throws IDMStoreException{
38 IIDMStore store = Mockito.mock(IIDMStore.class);
39 AAAIDMLightModule.setStore(store);
40 Domain domain = new Domain();
41 domain.setName("sdn");
42 domain.setDomainid("sdn");
44 Mockito.when(store.readDomain("sdn")).thenReturn(domain);
45 Creds c = new Creds();
46 Users users = new Users();
47 User user = new User();
48 user.setName("admin");
49 user.setUserid(c.username());
50 user.setDomainid("sdn");
52 user.setPassword(SHA256Calculator.getSHA256(c.password(),user.getSalt()));
53 List<User> lu = new LinkedList<>();
57 Grants grants = new Grants();
58 Grant grant = new Grant();
59 List<Grant> g = new ArrayList<>();
61 grant.setDomainid("sdn");
62 grant.setRoleid("admin");
63 grant.setUserid("admin");
65 Role role = new Role();
66 role.setRoleid("admin");
67 role.setName("admin");
68 Mockito.when(store.readRole("admin")).thenReturn(role);
69 Mockito.when(store.getUsers(c.username(), c.domain())).thenReturn(users);
70 Mockito.when(store.getGrants(c.domain(), c.username())).thenReturn(grants);
74 public void testPasswordHash(){
75 IdmLightProxy proxy = new IdmLightProxy();
76 proxy.authenticate(new Creds());
79 private static class Creds implements PasswordCredentials {
81 public String username() {
85 public String password() {
89 public String domain() {