From: Sai Gandham Date: Tue, 8 May 2018 15:00:13 +0000 (+0000) Subject: Improve code coverage for auth locate X-Git-Tag: Beijing-2.1.1~66 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=8bd730092a3dc34a09572ee2f13892a277023b59;p=aaf%2Fauthz.git Improve code coverage for auth locate Issue-ID: AAF-243 Change-Id: I00b38931fa683ca04d48f273f23b538c9a51a426 Signed-off-by: Sai Gandham --- diff --git a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java new file mode 100644 index 00000000..eea60eb0 --- /dev/null +++ b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java @@ -0,0 +1,115 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ +package org.onap.aaf.auth.locate; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.http.HttpStatus; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Answers; +import org.mockito.Mock; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.locate.facade.LocateFacade; +import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn; +import org.onap.aaf.cadi.principal.BasicPrincipal; +import org.onap.aaf.cadi.principal.X509Principal; +import org.onap.aaf.misc.env.LogTarget; + +public class JU_BasicAuthCodeTest { + + @Mock + AAFAuthn authn; + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + AuthzTrans trans; + + @Mock + HttpServletRequest req; + + @Mock + HttpServletResponse resp; + + @Mock + LogTarget error; + + @Mock + LocateFacade facade; + + @Mock + BasicPrincipal basicPrincipal; + @Mock + X509Principal x509Principal; + + @Before + public void setUp() throws Exception { + initMocks(this); + } + + @Test + public void testWithNullUserPrincipal() throws Exception { + BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade); + LocateCode locateCode = basicAuthCode.clone(facade, false); + + assertEquals(locateCode.desc(), basicAuthCode.desc()); + + when(trans.getUserPrincipal()).thenReturn(null); + when(trans.error()).thenReturn(error); + + basicAuthCode.handle(trans, req, resp); + } + + @Test + public void testWithBasicUserPrincipal() throws Exception { + BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade); + LocateCode locateCode = basicAuthCode.clone(facade, false); + + assertEquals(locateCode.desc(), basicAuthCode.desc()); + + when(trans.getUserPrincipal()).thenReturn(basicPrincipal); + + basicAuthCode.handle(trans, req, resp); + + verify(resp).setStatus(HttpStatus.OK_200); + } + + @Test + public void testWithX509UserPrincipal() throws Exception { + BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade); + LocateCode locateCode = basicAuthCode.clone(facade, false); + + assertEquals(locateCode.desc(), basicAuthCode.desc()); + + when(trans.getUserPrincipal()).thenReturn(x509Principal); + when(req.getHeader("Authorization")).thenReturn("Basic 76//76"); + + basicAuthCode.handle(trans, req, resp); + + verify(resp).setStatus(HttpStatus.FORBIDDEN_403); + } + +} diff --git a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java new file mode 100644 index 00000000..93b39b2d --- /dev/null +++ b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java @@ -0,0 +1,65 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ +package org.onap.aaf.auth.locate.mapper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.onap.aaf.auth.locate.mapper.Mapper.API; + +import locate.v1_0.Endpoints; +import locate.v1_0.MgmtEndpoints; +import locate_local.v1_0.Error; +import locate_local.v1_0.InRequest; +import locate_local.v1_0.Out; + +public class JU_Mapper_1_0Test { + + @Before + public void setUp() throws Exception { + + } + + @Test + public void testGetClasses() { + Mapper_1_0 mapper = new Mapper_1_0(); + assertEquals(InRequest.class, mapper.getClass(API.IN_REQ)); + assertEquals(Out.class, mapper.getClass(API.OUT)); + assertEquals(Error.class, mapper.getClass(API.ERROR)); + assertEquals(Void.class, mapper.getClass(API.VOID)); + assertEquals(Endpoints.class, mapper.getClass(API.ENDPOINTS)); + assertEquals(MgmtEndpoints.class, mapper.getClass(API.MGMT_ENDPOINTS)); + } + + @Test + public void testNewInstance() { + Mapper_1_0 mapper = new Mapper_1_0(); + assertTrue(mapper.newInstance(API.IN_REQ) instanceof InRequest); + assertTrue(mapper.newInstance(API.OUT) instanceof Out); + assertTrue(mapper.newInstance(API.ERROR) instanceof Error); + assertTrue(mapper.newInstance(API.ENDPOINTS) instanceof Endpoints); + assertTrue(mapper.newInstance(API.MGMT_ENDPOINTS) instanceof MgmtEndpoints); + assertEquals(null, mapper.newInstance(API.VOID)); + } + +} diff --git a/cadi/core/src/test/resources/output_key b/cadi/core/src/test/resources/output_key new file mode 100644 index 00000000..9d94dcbd --- /dev/null +++ b/cadi/core/src/test/resources/output_key @@ -0,0 +1 @@ +QRSTUVWXYZabcdef \ No newline at end of file diff --git a/cadi/core/test/output_key b/cadi/core/test/output_key new file mode 100644 index 00000000..353fabd2 --- /dev/null +++ b/cadi/core/test/output_key @@ -0,0 +1,27 @@ +g6wDq10CsnMUE0HB18N2UsrFri27TBG05Z1JzrvNSPUhIphFcv7gst-eHKvfbgffKF-rs9Zkjd5F +3FZDci9MlG4vhwrXHXLgo6DXEVH4FsfT5MP__E3yrnuGOcDI4kWUFdni3xG48PXNcT_xQoPb6JRO +dI3PiRRhgpvxuIL8O6iptFRoEilywvb8ySRFJA1XkRxCq-btzSpAHdMkBF-YnwMQYASveKXUddgo +Ab6Rvn6u8cDVWTIvmlEQe2el6dcKOOeMc5Ipc0AXsTLpGmhMVySEeyzKysHk0c1BiGxTulqZQcHP +L9uDFMxqL_GBwQOM4Xfu5wD_Dh1zNoKIpPta1AORjqlaUFOEsVWIn5oOKnimz4aNOjUku7tj3OKi +c-AsphXLIpmodQD4uZBynwhIjuNcJ3-SRZ3_SHnXqvf8gE-4jab2baMEX_QJ2GXumcOdZujDp8yz +3hCBlsToWXD-IatJ9dv_1gSn2_VOcXIhaNwe4YomaBVsQ4QqOkFWP9ZH3IfHrcCWZGt_HKg87NrJ +PASZ9yzlBLBTI7XFOg4rqU7l-b6-LpTLm36c0f5ImPzr-kHpE--y0cuTfdI4CEv3dJMGysKOfXax +N4tgR5t7ArQdFhLyo5mH-L5l973yuqJGVeRlTsYBYsHEb5vtIZxrYlebU9SSMmL9J-xI-hQV5tV7 +VR2C_zIKGL2nAq-tfVaiD1-M-SZW0S5VNmM-zXVxPT7jalCdHl6Dca47MhwQBVv_fxB5Nsahf10X +MT58fLLi7C2aCIAPqFyu0e3B_yuAnhDzd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