2 * Copyright (c) 2016 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.h2.persistence;
12 import java.sql.SQLException;
14 import org.junit.AfterClass;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19 import org.opendaylight.aaa.api.IDMStoreUtil;
20 import org.opendaylight.aaa.api.IIDMStore;
21 import org.opendaylight.aaa.api.model.Domain;
22 import org.opendaylight.aaa.api.model.Grant;
23 import org.opendaylight.aaa.api.model.Role;
24 import org.opendaylight.aaa.api.model.User;
26 public class H2StoreTest {
28 public static void start() {
29 File f = new File("idmlight.db.mv.db");
33 f = new File("idmlight.db.trace.db");
40 public static void end() {
41 File f = new File("idmlight.db.mv.db");
45 f = new File("idmlight.db.trace.db");
52 public void before() throws StoreException, SQLException {
53 UserStore us = new UserStore();
55 DomainStore ds = new DomainStore();
57 RoleStore rs = new RoleStore();
59 GrantStore gs = new GrantStore();
64 public void testCreateDefaultDomain() throws StoreException {
65 Domain d = new Domain();
66 Assert.assertEquals(true, d != null);
67 DomainStore ds = new DomainStore();
68 d.setName(IIDMStore.DEFAULT_DOMAIN);
70 d = ds.createDomain(d);
71 Assert.assertEquals(true, d != null);
75 public void testCreateTempRole() throws StoreException {
76 Role role = H2Store.createRole("temp", "temp domain", "Temp Testing role");
77 Assert.assertEquals(true, role != null);
81 public void testCreateUser() throws StoreException {
82 User user = H2Store.createUser("test", "pass", "domain", "desc", "email", true, "SALT");
83 Assert.assertEquals(true, user != null);
87 public void testCreateGrant() throws StoreException {
88 Domain d = H2Store.createDomain("sdn", true);
89 Role role = H2Store.createRole("temp", "temp domain", "Temp Testing role");
90 User user = H2Store.createUser("test", "pass", "domain", "desc", "email", true, "SALT");
91 Grant g = H2Store.createGrant(d.getDomainid(), user.getUserid(), role.getRoleid());
92 Assert.assertEquals(true, g != null);
96 public void testUpdatingUserEmail() throws StoreException {
97 UserStore us = new UserStore();
98 Domain d = H2Store.createDomain("sdn", true);
99 User user = H2Store.createUser("test", "pass", d.getDomainid(), "desc", "email", true,
102 user.setName("test");
103 user = us.putUser(user);
104 Assert.assertEquals(true, user != null);
106 user.setEmail("Test@Test.com");
107 user = us.putUser(user);
110 user.setName("test");
111 user.setDomainid(d.getDomainid());
112 user = us.getUser(IDMStoreUtil.createUserid(user.getName(), user.getDomainid()));
114 Assert.assertEquals("Test@Test.com", user.getEmail());
117 * @Test public void testCreateUserViaAPI() throws StoreException { Domain d
118 * = StoreBuilder.createDomain("sdn",true);
120 * User user = new User(); user.setName("Hello"); user.setPassword("Hello");
121 * user.setDomainid(d.getDomainid()); UserHandler h = new UserHandler();
122 * h.createUser(null, user);
124 * User u = new User(); u.setName("Hello"); u.setDomainid(d.getDomainid());
125 * UserStore us = new UserStore(); u =
126 * us.getUser(IDMStoreUtil.createUserid(u.getName(),u.getDomainid()));
128 * Assert.assertEquals(true, u != null); }
130 * @Test public void testUpdateUserViaAPI() throws StoreException { Domain d
131 * = StoreBuilder.createDomain("sdn",true);
133 * User user = new User(); user.setName("Hello"); user.setPassword("Hello");
134 * user.setDomainid(d.getDomainid()); UserHandler h = new UserHandler();
135 * h.createUser(null, user);
137 * user.setEmail("Hello@Hello.com"); user.setPassword("Test123");
138 * h.putUser(null, user, "" + user.getUserid());
140 * UserStore us = new UserStore();
142 * User u = new User(); u.setName("Hello"); u.setDomainid(d.getDomainid());
143 * u = us.getUser(IDMStoreUtil.createUserid(u.getName(),u.getDomainid()));
145 * Assert.assertEquals("Hello@Hello.com", u.getEmail());
147 * String hash = SHA256Calculator.getSHA256("Test123", u.getSalt());
148 * Assert.assertEquals(u.getPassword(), hash); }
150 * @Test public void testUpdateUserRoleViaAPI() throws StoreException {
151 * Domain d = StoreBuilder.createDomain("sdn",true); Role role1 =
152 * StoreBuilder.createRole("temp1",d.getDomainid(),"Temp Testing role");
154 * StoreBuilder.createRole("temp2",d.getDomainid(),"Temp Testing role");
156 * User user = new User(); user.setName("Hello"); user.setPassword("Hello");
157 * user.setDomainid(d.getDomainid());
159 * UserHandler h = new UserHandler(); h.createUser(null, user);
161 * user.setEmail("Hello@Hello.com"); user.setPassword("Test123");
162 * h.putUser(null, user, user.getUserid());
164 * Grant g = new Grant(); g.setUserid(user.getUserid());
165 * g.setDomainid(d.getDomainid()); g.setRoleid(role1.getRoleid());
166 * GrantStore gs = new GrantStore(); g = gs.createGrant(g);
168 * Assert.assertEquals(true, g != null); Assert.assertEquals(g.getRoleid(),
169 * role1.getRoleid());
171 * g = gs.deleteGrant(IDMStoreUtil.createGrantid(user.getUserid(),
172 * d.getDomainid(), role1.getRoleid())); g.setRoleid(role2.getRoleid()); g =
175 * Assert.assertEquals(true, g != null); Assert.assertEquals(g.getRoleid(),
176 * role2.getRoleid());
178 * User u = new User(); u.setName("Hello"); u.setDomainid(d.getDomainid());
179 * UserStore us = new UserStore(); u =
180 * us.getUser(IDMStoreUtil.createUserid(u.getName(),u.getDomainid()));
182 * Assert.assertEquals("Hello@Hello.com", u.getEmail());
184 * String hash = SHA256Calculator.getSHA256("Test123", u.getSalt());
185 * Assert.assertEquals(true, hash.equals(u.getPassword())); }