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.bouncycastle.asn1.x500.X500Name;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26 import org.junit.jupiter.api.extension.ExtendWith;
27 import org.onap.aaf.certservice.CertServiceApplication;
28 import org.onap.aaf.certservice.certification.configuration.model.Authentication;
29 import org.onap.aaf.certservice.certification.configuration.model.CaMode;
30 import org.onap.aaf.certservice.certification.configuration.model.Cmpv2Server;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.test.context.ContextConfiguration;
33 import org.springframework.test.context.junit.jupiter.SpringExtension;
35 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
36 import static org.junit.jupiter.api.Assertions.assertThrows;
38 @ExtendWith(SpringExtension.class)
39 @ContextConfiguration(classes = CertServiceApplication.class)
40 class Cmpv2ServerConfigurationValidatorTest {
43 private Cmpv2ServerConfigurationValidator validator;
45 private Authentication authentication;
46 private Cmpv2Server server;
51 setServerConfiguration();
55 public void givenValidServerDetailsWhenValidatingShouldNotThrowAnyException() {
57 assertDoesNotThrow(() -> validator.validate(server));
61 public void givenWrongProtocolInURLServerDetailsWhenValidatingShouldThrowException() {
63 server.setUrl("https://test.test.test:60000/");
66 assertThrows(IllegalArgumentException.class, () -> {validator.validate(server);});
70 public void givenWrongPortInURLServerDetailsWhenValidatingShouldThrowException() {
72 server.setUrl("http://test.test.test:70000/");
75 assertThrows(IllegalArgumentException.class, () -> validator.validate(server));
79 public void givenWrongCANameLengthInURLServerDetailsWhenValidatingShouldThrowException() {
84 assertThrows(IllegalArgumentException.class, () -> validator.validate(server));
88 public void givenWrongRVLengthInURLServerDetailsWhenValidatingShouldThrowException() {
90 authentication.setRv("");
93 assertThrows(IllegalArgumentException.class, () -> validator.validate(server));
97 public void givenWrongIAKLengthInURLServerDetailsWhenValidatingShouldThrowException() {
99 authentication.setIak("");
102 assertThrows(IllegalArgumentException.class, () -> validator.validate(server));
105 private void setServerConfiguration() {
106 server = new Cmpv2Server();
107 server.setCaMode(CaMode.CLIENT);
108 server.setCaName("TEST");
109 server.setIssuerDN(new X500Name("CN=ManagementCA"));
110 server.setUrl("http://127.0.0.1/ejbca/publicweb/cmp/cmp");
111 server.setAuthentication(authentication);
114 private void setAuthentication() {
115 authentication = new Authentication();
116 authentication.setRv("testRV");
117 authentication.setIak("testIAK");