X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Faaf%2Fv2_0%2Ftest%2FJU_AAFTrustChecker.java;h=64f4c9978dd0d124d0ee43cc5f7d1c32f8014592;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=1e469eca6d669c556c8c24c1a30991efdffc83eb;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AAFTrustChecker.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AAFTrustChecker.java index 1e469eca..64f4c997 100644 --- a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AAFTrustChecker.java +++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AAFTrustChecker.java @@ -47,84 +47,84 @@ import org.onap.aaf.misc.env.Env; public class JU_AAFTrustChecker { - private final static String type = "type"; - private final static String instance = "instance"; - private final static String action = "action"; - private final static String key = type + '|' + instance + '|' + action; - private final static String name = "name"; - private final static String otherName = "otherName"; - - private PropAccess access; - - @Mock private Env envMock; - @Mock private TafResp trespMock; - @Mock private HttpServletRequest reqMock; - @Mock private TaggedPrincipal tpMock; - @Mock private Lur lurMock; - @Mock private TaggedPrincipal princMock; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); - } - - @Test - public void test() { - AAFTrustChecker trustChecker; - - // coverage calls - trustChecker = new AAFTrustChecker(access); - trustChecker = new AAFTrustChecker(envMock); - - access.setProperty(Config.CADI_TRUST_PERM, "example"); - when(envMock.getProperty(Config.CADI_TRUST_PERM)).thenReturn("example"); - trustChecker = new AAFTrustChecker(access); - trustChecker = new AAFTrustChecker(envMock); - - access.setProperty(Config.CADI_TRUST_PERM, key); - when(envMock.getProperty(Config.CADI_TRUST_PERM)).thenReturn(key); - trustChecker = new AAFTrustChecker(access); - trustChecker = new AAFTrustChecker(envMock); - - trustChecker.setLur(lurMock); - - assertThat(trustChecker.mayTrust(trespMock, reqMock), is(trespMock)); - - when(reqMock.getHeader(null)).thenReturn("comma,comma,comma"); - assertThat(trustChecker.mayTrust(trespMock, reqMock), is(trespMock)); - - when(reqMock.getHeader(null)).thenReturn("colon:colon:colon:colon,comma,comma"); - assertThat(trustChecker.mayTrust(trespMock, reqMock), is(trespMock)); - - when(reqMock.getHeader(null)).thenReturn("colon:colon:colon:AS,comma,comma"); - when(trespMock.getPrincipal()).thenReturn(tpMock); - when(tpMock.getName()).thenReturn(name); - when(lurMock.fish(princMock, null)).thenReturn(true); - TafResp tntResp = trustChecker.mayTrust(trespMock, reqMock); - - assertThat(tntResp instanceof TrustNotTafResp, is(true)); - assertThat(tntResp.toString(), is("name requested trust as colon, but does not have Authorization")); - - when(reqMock.getHeader(null)).thenReturn(name + ":colon:colon:AS,comma,comma"); - assertThat(trustChecker.mayTrust(trespMock, reqMock), is(trespMock)); - - when(envMock.getProperty(Config.CADI_ALIAS, null)).thenReturn(name); - when(envMock.getProperty(Config.CADI_TRUST_PERM)).thenReturn(null); - trustChecker = new AAFTrustChecker(envMock); - trustChecker.setLur(lurMock); - - when(trespMock.getPrincipal()).thenReturn(princMock); - when(princMock.getName()).thenReturn(otherName); - when(lurMock.fish(princMock, null)).thenReturn(true); - TafResp ttResp = trustChecker.mayTrust(trespMock, reqMock); - assertThat(ttResp instanceof TrustTafResp, is(true)); - assertThat(ttResp.toString(), is(name + " by trust of " + name + " validated using colon by colon, null")); - - when(princMock.getName()).thenReturn(name); - ttResp = trustChecker.mayTrust(trespMock, reqMock); - assertThat(ttResp instanceof TrustTafResp, is(true)); - assertThat(ttResp.toString(), is(name + " by trust of " + name + " validated using colon by colon, null")); - } + private final static String type = "type"; + private final static String instance = "instance"; + private final static String action = "action"; + private final static String key = type + '|' + instance + '|' + action; + private final static String name = "name"; + private final static String otherName = "otherName"; + + private PropAccess access; + + @Mock private Env envMock; + @Mock private TafResp trespMock; + @Mock private HttpServletRequest reqMock; + @Mock private TaggedPrincipal tpMock; + @Mock private Lur lurMock; + @Mock private TaggedPrincipal princMock; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); + } + + @Test + public void test() { + AAFTrustChecker trustChecker; + + // coverage calls + trustChecker = new AAFTrustChecker(access); + trustChecker = new AAFTrustChecker(envMock); + + access.setProperty(Config.CADI_TRUST_PERM, "example"); + when(envMock.getProperty(Config.CADI_TRUST_PERM)).thenReturn("example"); + trustChecker = new AAFTrustChecker(access); + trustChecker = new AAFTrustChecker(envMock); + + access.setProperty(Config.CADI_TRUST_PERM, key); + when(envMock.getProperty(Config.CADI_TRUST_PERM)).thenReturn(key); + trustChecker = new AAFTrustChecker(access); + trustChecker = new AAFTrustChecker(envMock); + + trustChecker.setLur(lurMock); + + assertThat(trustChecker.mayTrust(trespMock, reqMock), is(trespMock)); + + when(reqMock.getHeader(null)).thenReturn("comma,comma,comma"); + assertThat(trustChecker.mayTrust(trespMock, reqMock), is(trespMock)); + + when(reqMock.getHeader(null)).thenReturn("colon:colon:colon:colon,comma,comma"); + assertThat(trustChecker.mayTrust(trespMock, reqMock), is(trespMock)); + + when(reqMock.getHeader(null)).thenReturn("colon:colon:colon:AS,comma,comma"); + when(trespMock.getPrincipal()).thenReturn(tpMock); + when(tpMock.getName()).thenReturn(name); + when(lurMock.fish(princMock, null)).thenReturn(true); + TafResp tntResp = trustChecker.mayTrust(trespMock, reqMock); + + assertThat(tntResp instanceof TrustNotTafResp, is(true)); + assertThat(tntResp.toString(), is("name requested trust as colon, but does not have Authorization")); + + when(reqMock.getHeader(null)).thenReturn(name + ":colon:colon:AS,comma,comma"); + assertThat(trustChecker.mayTrust(trespMock, reqMock), is(trespMock)); + + when(envMock.getProperty(Config.CADI_ALIAS, null)).thenReturn(name); + when(envMock.getProperty(Config.CADI_TRUST_PERM)).thenReturn(null); + trustChecker = new AAFTrustChecker(envMock); + trustChecker.setLur(lurMock); + + when(trespMock.getPrincipal()).thenReturn(princMock); + when(princMock.getName()).thenReturn(otherName); + when(lurMock.fish(princMock, null)).thenReturn(true); + TafResp ttResp = trustChecker.mayTrust(trespMock, reqMock); + assertThat(ttResp instanceof TrustTafResp, is(true)); + assertThat(ttResp.toString(), is(name + " by trust of " + name + " validated using colon by colon, null")); + + when(princMock.getName()).thenReturn(name); + ttResp = trustChecker.mayTrust(trespMock, reqMock); + assertThat(ttResp instanceof TrustTafResp, is(true)); + assertThat(ttResp.toString(), is(name + " by trust of " + name + " validated using colon by colon, null")); + } }