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 ******************************************************************************/
22 package org.onap.aaf.auth.service.validation.test;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
27 import java.util.HashSet;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.aaf.auth.dao.cass.PermDAO;
33 import org.onap.aaf.auth.dao.cass.RoleDAO;
34 import org.onap.aaf.auth.layer.Result;
35 import org.onap.aaf.auth.service.validation.ServiceValidator;
36 import org.onap.aaf.auth.validation.Validator;
38 public class JU_ServiceValidator {
40 ServiceValidator validator;
44 validator = new ServiceValidator();
48 public void permNotOk() {
50 Result<PermDAO.Data> rpd = Result.err(1, "ERR_Security");
53 assertTrue(validator.errs().equals("ERR_Security\n"));
58 public void permInstance() {
59 assertFalse(validator.permInstance("hello").err());
60 assertFalse(validator.permInstance("hello32").err());
61 assertFalse(validator.permInstance("hello-32").err());
62 assertFalse(validator.permInstance(":asdf:*:sdf*:sdk").err());
63 assertFalse(validator.permInstance(":asdf:*:sdf*:sdk*").err());
64 // Perms may not end in ":"
65 assertTrue(validator.permInstance(":").err());
66 assertTrue(validator.permInstance(":hello:").err());
70 public void permOkNull() {
72 Result rpd = Result.ok();
75 assertTrue(validator.errs().equals("Perm Data is null.\n"));
80 public void roleOkNull() {
82 Result rrd = Result.ok();
85 assertTrue(validator.errs().equals("Role Data is null.\n"));
89 public void roleOk() {
90 RoleDAO.Data to = new RoleDAO.Data();
93 to.description = "description";
94 Set<String> permissions = new HashSet<String>();
95 permissions.add("perm1");
96 to.perms = permissions;
98 Result<RoleDAO.Data> rrd = Result.ok(to);
102 validator.errs().equals("Perm [perm1] in Role [namespace.name] is not correctly separated with '|'\n"));
106 public void roleNotOk() {
108 Result rrd = Result.err(1, "ERR_Security");
111 assertTrue(validator.errs().equals("ERR_Security\n"));