1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * * ===========================================================================
7 * * Licensed under the Apache License, Version 2.0 (the "License");
8 * * you may not use this file except in compliance with the License.
9 * * You may obtain a copy of the License at
11 * * http://www.apache.org/licenses/LICENSE-2.0
13 * * Unless required by applicable law or agreed to in writing, software
14 * * distributed under the License is distributed on an "AS IS" BASIS,
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * * See the License for the specific language governing permissions and
17 * * limitations under the License.
18 * * ============LICENSE_END====================================================
21 ******************************************************************************/
23 package org.onap.aaf.auth.service.validation.test;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertTrue;
28 import java.util.HashSet;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.aaf.auth.dao.cass.PermDAO;
34 import org.onap.aaf.auth.dao.cass.RoleDAO;
35 import org.onap.aaf.auth.layer.Result;
36 import org.onap.aaf.auth.service.validation.ServiceValidator;
37 import org.onap.aaf.auth.validation.Validator;
39 public class JU_ServiceValidator {
41 ServiceValidator validator;
45 validator = new ServiceValidator();
49 public void permNotOk() {
51 Result<PermDAO.Data> rpd = Result.err(1, "ERR_Security");
54 assertTrue(validator.errs().equals("ERR_Security\n"));
59 public void permInstance() {
60 assertFalse(validator.permInstance("hello").err());
61 assertFalse(validator.permInstance("hello32").err());
62 assertFalse(validator.permInstance("hello-32").err());
63 assertFalse(validator.permInstance(":asdf:*:sdf*:sdk").err());
64 assertFalse(validator.permInstance(":asdf:*:sdf*:sdk*").err());
65 // Perms may not end in ":"
66 assertTrue(validator.permInstance(":").err());
67 assertTrue(validator.permInstance(":hello:").err());
71 public void permOkNull() {
73 Result rpd = Result.ok();
76 assertTrue(validator.errs().equals("Perm Data is null.\n"));
81 public void roleOkNull() {
83 Result rrd = Result.ok();
86 assertTrue(validator.errs().equals("Role Data is null.\n"));
90 public void roleOk() {
91 RoleDAO.Data to = new RoleDAO.Data();
94 to.description = "description";
95 Set<String> permissions = new HashSet<>();
96 permissions.add("perm1");
97 to.perms = permissions;
99 Result<RoleDAO.Data> rrd = Result.ok(to);
103 validator.errs().equals("Perm [perm1] in Role [namespace.name] is not correctly separated with '|'\n"));
107 public void roleNotOk() {
109 Result rrd = Result.err(1, "ERR_Security");
112 assertTrue(validator.errs().equals("ERR_Security\n"));