2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia. 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 package org.onap.aaf.certservice.certification.configuration.validation;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25 import org.junit.jupiter.api.extension.ExtendWith;
26 import org.onap.aaf.certservice.CertServiceApplication;
27 import org.onap.aaf.certservice.certification.configuration.model.Authentication;
28 import org.onap.aaf.certservice.certification.configuration.model.CaMode;
29 import org.onap.aaf.certservice.certification.configuration.model.Cmpv2Server;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.test.context.ContextConfiguration;
32 import org.springframework.test.context.junit.jupiter.SpringExtension;
34 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
35 import static org.junit.jupiter.api.Assertions.assertThrows;
37 @ExtendWith(SpringExtension.class)
38 @ContextConfiguration(classes = CertServiceApplication.class)
39 class Cmpv2ServerConfigurationValidatorTest {
42 private Cmpv2ServerConfigurationValidator validator;
44 private Authentication authentication;
45 private Cmpv2Server server;
50 setServerConfiguration();
54 public void givenValidServerDetailsWhenValidatingShouldNotThrowAnyException() {
56 assertDoesNotThrow(() -> validator.validate(server));
60 public void givenWrongProtocolInURLServerDetailsWhenValidatingShouldThrowException() {
62 server.setUrl("https://test.test.test:60000/");
65 assertThrows(IllegalArgumentException.class, () -> {validator.validate(server);});
69 public void givenWrongPortInURLServerDetailsWhenValidatingShouldThrowException() {
71 server.setUrl("http://test.test.test:70000/");
74 assertThrows(IllegalArgumentException.class, () -> validator.validate(server));
78 public void givenWrongCANameLengthInURLServerDetailsWhenValidatingShouldThrowException() {
83 assertThrows(IllegalArgumentException.class, () -> validator.validate(server));
87 public void givenWrongIssuerDNLengthInURLServerDetailsWhenValidatingShouldThrowException() {
89 server.setIssuerDN("123");
92 assertThrows(IllegalArgumentException.class, () -> validator.validate(server));
96 public void givenWrongRVLengthInURLServerDetailsWhenValidatingShouldThrowException() {
98 authentication.setRv("");
101 assertThrows(IllegalArgumentException.class, () -> validator.validate(server));
105 public void givenWrongIAKLengthInURLServerDetailsWhenValidatingShouldThrowException() {
107 authentication.setIak("");
110 assertThrows(IllegalArgumentException.class, () -> validator.validate(server));
113 private void setServerConfiguration() {
114 server = new Cmpv2Server();
115 server.setCaMode(CaMode.CLIENT);
116 server.setCaName("TEST");
117 server.setIssuerDN("CN=ManagementCA");
118 server.setUrl("http://127.0.0.1/ejbca/publicweb/cmp/cmp");
119 server.setAuthentication(authentication);
122 private void setAuthentication() {
123 authentication = new Authentication();
124 authentication.setRv("testRV");
125 authentication.setIak("testIAK");