From 781c2968e7a2878d652d3de4428f5886925c0dfa Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Tue, 20 Feb 2018 22:33:54 -0500 Subject: [PATCH 01/16] Catch Exception Tried to test if the exception is thrown --- ...stDefaultIntrospectionResultAssembler.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java index 4357bc64b..e287c644c 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java @@ -149,8 +149,8 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(equalTo(expected))); } - @Test - public void shouldAssembleExpectedResultForAccessTokenWithoutExpiry() { + @Test (expected = ParseException.class) + public void shouldAssembleExpectedResultForAccessTokenWithoutExpiry() throws Throwable { // given OAuth2AccessTokenEntity accessToken = accessToken(null, scopes("foo", "bar"), null, "Bearer", @@ -174,8 +174,23 @@ public class TestDefaultIntrospectionResultAssembler { .put("token_type", "Bearer") .build(); assertThat(result, is(equalTo(expected))); + assertFalse(throwException()); + } + + private void assertFalse(boolean throwException) { + } + private boolean throwException() throws ParseException{ + throw new ParseException(null, 0); + + } + + + + + + @Test public void shouldAssembleExpectedResultForAccessTokenWithoutUserAuthentication() throws ParseException { // given @@ -255,8 +270,8 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(equalTo(expected))); } - @Test - public void shouldAssembleExpectedResultForRefreshTokenWithoutExpiry() { + @Test(expected = ParseException.class) + public void shouldAssembleExpectedResultForRefreshTokenWithoutExpiry() Throwable{ // given OAuth2RefreshTokenEntity refreshToken = refreshToken(null, From 98a38f87c008f02b24efbffe918a324edeaaa3ea Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Thu, 22 Feb 2018 18:55:45 -0500 Subject: [PATCH 02/16] Added few test cases to TestDefaultSystemScopeService file --- .../impl/TestDefaultSystemScopeService.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java index 96f74074f..8aba1073f 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java @@ -184,6 +184,60 @@ public class TestDefaultSystemScopeService { // extra scope (fail) assertThat(service.scopesMatch(expected, actualBad), is(false)); + + } + + @Test + public void getremoveRestrictedAndReservedScopes() { + + Set restrictedAndReservedScopes = Sets.newHashSet(defaultDynScope1, defaultDynScope2, dynScope1); + assertThat(service.removeRestrictedAndReservedScopes(allScopes),equalTo(restrictedAndReservedScopes)); + } + + @Test + public void getremoveReservedScopes() { + Set removeReservedScopes = Sets.newHashSet(defaultDynScope2, defaultDynScope1, defaultScope2,restrictedScope1,defaultScope1,dynScope1); + assertThat(service.removeReservedScopes(allScopes), equalTo(removeReservedScopes)); + } + + @Test + public void getById() { + + // check null condition + + assertThat(service.getById((long) 60), is(nullValue())); + + + } + + @Test + public void getByValue() { + + // check null condition + + assertThat(service.getByValue("defaultDynScope1String"), is(nullValue())); + + + } + + @Test + public void save() { + + // check null condition + + assertThat(service.save(defaultScope1), is(nullValue())); + + + + } + + @Test + public void getReserved() { + //Set restricted = Sets.newHashSet(defaultScope1, defaultScope2, restrictedScope1); + Set reserved = service.getReserved(); + assertThat(service.getReserved(), equalTo(reserved)); + } + } From 1da511c6a7ddace0a1b5bb7e5b1e4f1e957256c2 Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Thu, 22 Feb 2018 20:19:05 -0500 Subject: [PATCH 03/16] Update TestDefaultIntrospectionResultAssembler.java --- ...stDefaultIntrospectionResultAssembler.java | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java index e287c644c..bf9351ad4 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java @@ -149,8 +149,8 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(equalTo(expected))); } - @Test (expected = ParseException.class) - public void shouldAssembleExpectedResultForAccessTokenWithoutExpiry() throws Throwable { + @Test + public void shouldAssembleExpectedResultForAccessTokenWithoutExpiry() { // given OAuth2AccessTokenEntity accessToken = accessToken(null, scopes("foo", "bar"), null, "Bearer", @@ -174,22 +174,8 @@ public class TestDefaultIntrospectionResultAssembler { .put("token_type", "Bearer") .build(); assertThat(result, is(equalTo(expected))); - assertFalse(throwException()); } - private void assertFalse(boolean throwException) { - - } - - private boolean throwException() throws ParseException{ - throw new ParseException(null, 0); - - } - - - - - @Test public void shouldAssembleExpectedResultForAccessTokenWithoutUserAuthentication() throws ParseException { @@ -270,8 +256,8 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(equalTo(expected))); } - @Test(expected = ParseException.class) - public void shouldAssembleExpectedResultForRefreshTokenWithoutExpiry() Throwable{ + @Test + public void shouldAssembleExpectedResultForRefreshTokenWithoutExpiry(){ // given OAuth2RefreshTokenEntity refreshToken = refreshToken(null, From f1c0b3a460475e1183e6e1dd9114d934d2f634d6 Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Mon, 26 Feb 2018 20:21:02 -0500 Subject: [PATCH 04/16] Updated TestDefaultSystemScopeService.java Changed few test names and @Test getReserveScopes() --- .../service/impl/TestDefaultSystemScopeService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java index 8aba1073f..a47b8dac3 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java @@ -201,7 +201,7 @@ public class TestDefaultSystemScopeService { } @Test - public void getById() { + public void getById_notfound() { // check null condition @@ -211,7 +211,7 @@ public class TestDefaultSystemScopeService { } @Test - public void getByValue() { + public void getByValue_notfound() { // check null condition @@ -221,20 +221,20 @@ public class TestDefaultSystemScopeService { } @Test - public void save() { + public void save_scope() { // check null condition assertThat(service.save(defaultScope1), is(nullValue())); + assertThat(service.save(mySystemScope), equalTo(mySystemScope)); } @Test - public void getReserved() { - //Set restricted = Sets.newHashSet(defaultScope1, defaultScope2, restrictedScope1); - Set reserved = service.getReserved(); + public void getReserveScopes() { + Set reserved = SystemScopeService.reservedScopes; assertThat(service.getReserved(), equalTo(reserved)); } From a7ce3eb28248b977785de2973302403b120091fb Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Thu, 1 Mar 2018 19:43:32 -0500 Subject: [PATCH 05/16] Made changes in save_scope() and getReserveScopes() --- .../service/impl/TestDefaultSystemScopeService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java index a47b8dac3..ba333eeda 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java @@ -221,21 +221,21 @@ public class TestDefaultSystemScopeService { } @Test - public void save_scope() { + public void save_null() { // check null condition assertThat(service.save(defaultScope1), is(nullValue())); - assertThat(service.save(mySystemScope), equalTo(mySystemScope)); - - + } + @Test + public void save_value(){ + assertThat(service.save(mySystemScope), equalTo(mySystemScope)) } @Test public void getReserveScopes() { - Set reserved = SystemScopeService.reservedScopes; - assertThat(service.getReserved(), equalTo(reserved)); + assertThat(service.getReserved(), equalTo(SystemScopeService.reservedScopes)); } From f26f6db319340fddf77725ae705ae3a095ce9d92 Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Sun, 4 Mar 2018 11:49:24 -0500 Subject: [PATCH 06/16] Update TestDefaultSystemScopeService.java --- .../impl/TestDefaultSystemScopeService.java | 56 +------------------ 1 file changed, 1 insertion(+), 55 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java index ba333eeda..808d96b58 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright 2017 The MIT Internet Trust Consortium + * Copyright 2018 The MIT Internet Trust Consortium * * Portions copyright 2011-2013 The MITRE Corporation * @@ -184,60 +184,6 @@ public class TestDefaultSystemScopeService { // extra scope (fail) assertThat(service.scopesMatch(expected, actualBad), is(false)); - } - - @Test - public void getremoveRestrictedAndReservedScopes() { - - Set restrictedAndReservedScopes = Sets.newHashSet(defaultDynScope1, defaultDynScope2, dynScope1); - assertThat(service.removeRestrictedAndReservedScopes(allScopes),equalTo(restrictedAndReservedScopes)); - } - - @Test - public void getremoveReservedScopes() { - Set removeReservedScopes = Sets.newHashSet(defaultDynScope2, defaultDynScope1, defaultScope2,restrictedScope1,defaultScope1,dynScope1); - assertThat(service.removeReservedScopes(allScopes), equalTo(removeReservedScopes)); - } - - @Test - public void getById_notfound() { - - // check null condition - - assertThat(service.getById((long) 60), is(nullValue())); - - - } - - @Test - public void getByValue_notfound() { - - // check null condition - - assertThat(service.getByValue("defaultDynScope1String"), is(nullValue())); - - - } - - @Test - public void save_null() { - - // check null condition - - assertThat(service.save(defaultScope1), is(nullValue())); - } - - @Test - public void save_value(){ - assertThat(service.save(mySystemScope), equalTo(mySystemScope)) - } - - @Test - public void getReserveScopes() { - assertThat(service.getReserved(), equalTo(SystemScopeService.reservedScopes)); - - } - } From e0038e3462b46f5814784804d54f1e349f309587 Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Sun, 4 Mar 2018 13:56:54 -0500 Subject: [PATCH 07/16] Pushing local changes to the remote repository for TestDefaultSystemScopeService --- .../impl/TestDefaultSystemScopeService.java | 63 ++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java index 808d96b58..6c3063416 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright 2018 The MIT Internet Trust Consortium + * Copyright 2017 The MIT Internet Trust Consortium * * Portions copyright 2011-2013 The MITRE Corporation * @@ -24,6 +24,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mitre.oauth2.model.SystemScope; import org.mitre.oauth2.repository.SystemScopeRepository; +import org.mitre.oauth2.service.SystemScopeService; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; @@ -34,6 +35,8 @@ import com.google.common.collect.Sets; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.CoreMatchers.notNullValue; + import static org.junit.Assert.assertThat; @@ -51,7 +54,8 @@ public class TestDefaultSystemScopeService { private SystemScope defaultScope2; private SystemScope dynScope1; private SystemScope restrictedScope1; - + private SystemScope mySystemScope; + private String defaultDynScope1String = "defaultDynScope1"; private String defaultDynScope2String = "defaultDynScope2"; private String defaultScope1String = "defaultScope1"; @@ -64,6 +68,7 @@ public class TestDefaultSystemScopeService { private Set allScopesWithValue; private Set allScopeStringsWithValue; + @Mock private SystemScopeRepository repository; @@ -83,7 +88,9 @@ public class TestDefaultSystemScopeService { defaultDynScope2 = new SystemScope(defaultDynScope2String); defaultDynScope1.setDefaultScope(true); defaultDynScope2.setDefaultScope(true); + mySystemScope = new SystemScope(); + // two strictly default scopes (restricted) defaultScope1 = new SystemScope(defaultScope1String); defaultScope2 = new SystemScope(defaultScope2String); @@ -114,6 +121,8 @@ public class TestDefaultSystemScopeService { Mockito.when(repository.getByValue(restrictedScope1String)).thenReturn(restrictedScope1); Mockito.when(repository.getAll()).thenReturn(allScopes); + Mockito.when(repository.save(mySystemScope)).thenReturn(mySystemScope); + } @Test @@ -185,5 +194,55 @@ public class TestDefaultSystemScopeService { // extra scope (fail) assertThat(service.scopesMatch(expected, actualBad), is(false)); } + + @Test + public void removeRestrictedAndReservedScopes() { + + Set unRestrictedScopes = Sets.newHashSet(defaultDynScope1, defaultDynScope2, dynScope1); + assertThat(service.removeRestrictedAndReservedScopes(allScopes),equalTo(unRestrictedScopes)); + } + + @Test + public void removeReservedScopes() { + Set unReservedScopes = Sets.newHashSet(defaultDynScope2, defaultDynScope1, defaultScope2,restrictedScope1,defaultScope1,dynScope1); + assertThat(service.removeReservedScopes(allScopes), equalTo(unReservedScopes)); + } + + @Test + public void getById_notfound() { + + // check null condition + assertThat(service.getById((long) 60), is(nullValue())); + + + } + + @Test + public void getByValue_notfound() { + + // check null condition + + assertThat(service.getByValue("defaultDynScope1String"), is(nullValue())); + + + } + + @Test + public void save_null() { + // check null condition + assertThat(service.save(defaultScope1), is(nullValue())); + + } + + @Test + public void save_value() { + assertThat(service.save(mySystemScope), equalTo(mySystemScope)); + } + + @Test + public void getReserveScopes() { + assertThat(service.getReserved(), equalTo(SystemScopeService.reservedScopes)); + + } } From 3b4625f40809f577a01040fc901d5e39ce1e1b11 Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Sat, 17 Mar 2018 16:55:20 -0400 Subject: [PATCH 08/16] changes to save method Made changes to save method referring comments. --- .../oauth2/service/impl/TestDefaultSystemScopeService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java index 6c3063416..427bf4a1e 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java @@ -55,6 +55,7 @@ public class TestDefaultSystemScopeService { private SystemScope dynScope1; private SystemScope restrictedScope1; private SystemScope mySystemScope; + private SystemScope myrSystemScope; private String defaultDynScope1String = "defaultDynScope1"; private String defaultDynScope2String = "defaultDynScope2"; @@ -121,7 +122,7 @@ public class TestDefaultSystemScopeService { Mockito.when(repository.getByValue(restrictedScope1String)).thenReturn(restrictedScope1); Mockito.when(repository.getAll()).thenReturn(allScopes); - Mockito.when(repository.save(mySystemScope)).thenReturn(mySystemScope); + Mockito.when(repository.save(mySystemScope)).thenReturn(myrSystemScope); } @@ -237,7 +238,7 @@ public class TestDefaultSystemScopeService { @Test public void save_value() { - assertThat(service.save(mySystemScope), equalTo(mySystemScope)); + assertThat(service.save(mySystemScope), equalTo(myrSystemScope)); } @Test From e6bed2a481ee3a086ae3e73a16018a111648396d Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Sat, 17 Mar 2018 17:06:04 -0400 Subject: [PATCH 09/16] changes to save method --- .../mitre/oauth2/service/impl/TestDefaultSystemScopeService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java index 427bf4a1e..ab7b98d0e 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java @@ -90,6 +90,7 @@ public class TestDefaultSystemScopeService { defaultDynScope1.setDefaultScope(true); defaultDynScope2.setDefaultScope(true); mySystemScope = new SystemScope(); + myrSystemScope = new SystemScope(); // two strictly default scopes (restricted) From 003fbed43eb8a1eaea756380e0c205c7e1502610 Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Fri, 23 Mar 2018 09:22:57 -0400 Subject: [PATCH 10/16] Update TestDefaultIntrospectionResultAssembler.java I have passed userInfo as null paramter and i am using parameters which are already used in the existing test cases. I have taken references from other test cases which are similar to @test(expected= error.class) format. Can you Kindly go through the test case and guide if this is the correct way and how to deal with parameter in this case. --- .../impl/TestDefaultIntrospectionResultAssembler.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java index bf9351ad4..141eb9aa4 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java @@ -303,8 +303,18 @@ public class TestDefaultIntrospectionResultAssembler { .build(); assertThat(result, is(equalTo(expected))); } + + @Test(expected = ParseException.class) + public void testAssembleFrom_refresh() { + OAuth2RefreshTokenEntity refreshToken = refreshToken(null, + oauth2AuthenticationWithUser(oauth2Request("clientId", scopes("foo", "bar")), "name")); + Set authScopes = scopes("foo", "bar", "baz"); + // this should fail with an error + assembler.assembleFrom(refreshToken, null , authScopes); + + } private UserInfo userInfo(String sub) { UserInfo userInfo = mock(UserInfo.class); From e697ac8d7a644754bc8673caecda3123aca31e95 Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Tue, 10 Apr 2018 15:59:48 -0400 Subject: [PATCH 11/16] Update TestDefaultSystemScopeService.java made changes to save method --- .../service/impl/TestDefaultSystemScopeService.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java index ab7b98d0e..63b5d7bb7 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java @@ -55,7 +55,7 @@ public class TestDefaultSystemScopeService { private SystemScope dynScope1; private SystemScope restrictedScope1; private SystemScope mySystemScope; - private SystemScope myrSystemScope; + private SystemScope mysavedSystemScope; private String defaultDynScope1String = "defaultDynScope1"; private String defaultDynScope2String = "defaultDynScope2"; @@ -63,6 +63,7 @@ public class TestDefaultSystemScopeService { private String defaultScope2String = "defaultScope2"; private String dynScope1String = "dynScope1"; private String restrictedScope1String = "restrictedScope1"; + private String mysavedSystemScopeString = "mysavedSystemScope"; private Set allScopes; private Set allScopeStrings; @@ -90,7 +91,7 @@ public class TestDefaultSystemScopeService { defaultDynScope1.setDefaultScope(true); defaultDynScope2.setDefaultScope(true); mySystemScope = new SystemScope(); - myrSystemScope = new SystemScope(); + mysavedSystemScope = new SystemScope(mysavedSystemScopeString); // two strictly default scopes (restricted) @@ -123,7 +124,7 @@ public class TestDefaultSystemScopeService { Mockito.when(repository.getByValue(restrictedScope1String)).thenReturn(restrictedScope1); Mockito.when(repository.getAll()).thenReturn(allScopes); - Mockito.when(repository.save(mySystemScope)).thenReturn(myrSystemScope); + Mockito.when(repository.save(mySystemScope)).thenReturn(mysavedSystemScope); } @@ -239,7 +240,7 @@ public class TestDefaultSystemScopeService { @Test public void save_value() { - assertThat(service.save(mySystemScope), equalTo(myrSystemScope)); + assertThat(service.save(mySystemScope), equalTo(mysavedSystemScope)); } @Test From 9f9e778d93ce74c191adcb401e7a2b83e816dbf8 Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Tue, 17 Apr 2018 07:22:29 -0400 Subject: [PATCH 12/16] Update TestDefaultSystemScopeService.java --- .../service/impl/TestDefaultSystemScopeService.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java index 63b5d7bb7..0622e89d3 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultSystemScopeService.java @@ -55,7 +55,7 @@ public class TestDefaultSystemScopeService { private SystemScope dynScope1; private SystemScope restrictedScope1; private SystemScope mySystemScope; - private SystemScope mysavedSystemScope; + private SystemScope mySavedSystemScope; private String defaultDynScope1String = "defaultDynScope1"; private String defaultDynScope2String = "defaultDynScope2"; @@ -63,7 +63,7 @@ public class TestDefaultSystemScopeService { private String defaultScope2String = "defaultScope2"; private String dynScope1String = "dynScope1"; private String restrictedScope1String = "restrictedScope1"; - private String mysavedSystemScopeString = "mysavedSystemScope"; + private String mySavedSystemScopeString = "mySavedSystemScope"; private Set allScopes; private Set allScopeStrings; @@ -91,7 +91,7 @@ public class TestDefaultSystemScopeService { defaultDynScope1.setDefaultScope(true); defaultDynScope2.setDefaultScope(true); mySystemScope = new SystemScope(); - mysavedSystemScope = new SystemScope(mysavedSystemScopeString); + mySavedSystemScope = new SystemScope(mySavedSystemScopeString); // two strictly default scopes (restricted) @@ -124,7 +124,7 @@ public class TestDefaultSystemScopeService { Mockito.when(repository.getByValue(restrictedScope1String)).thenReturn(restrictedScope1); Mockito.when(repository.getAll()).thenReturn(allScopes); - Mockito.when(repository.save(mySystemScope)).thenReturn(mysavedSystemScope); + Mockito.when(repository.save(mySystemScope)).thenReturn(mySavedSystemScope); } @@ -240,7 +240,7 @@ public class TestDefaultSystemScopeService { @Test public void save_value() { - assertThat(service.save(mySystemScope), equalTo(mysavedSystemScope)); + assertThat(service.save(mySystemScope), equalTo(mySavedSystemScope)); } @Test From c7cacbbe65f4371054afa6ab32c022c02cc60f3f Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Sun, 22 Apr 2018 18:42:42 -0400 Subject: [PATCH 13/16] Update TestDefaultIntrospectionResultAssembler.java Hi Justin, I am trying to throw a ParseException where the actual value and expected value are not equal for the expiration parameters. I am trying to test the catch block. I have used the same parameters which are already used in other test cases in the same file. Can you please guide me on how to approach catch case in this particular scenario, I have already tried but I am not sure this is the right way. Thank you --- ...stDefaultIntrospectionResultAssembler.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java index 141eb9aa4..d8d072798 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java @@ -304,16 +304,32 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(equalTo(expected))); } - @Test(expected = ParseException.class) - public void testAssembleFrom_refresh() { + @Test(expected=ParseException.class) + public void testAssembleFrom_OAuth2AccessTokenEntityExpiration() { + + // given + OAuth2AccessTokenEntity accessToken = accessToken(null, scopes("foo", "bar"), null, "Bearer", + oauth2AuthenticationWithUser(oauth2Request("clientId"), "name")); - OAuth2RefreshTokenEntity refreshToken = refreshToken(null, - oauth2AuthenticationWithUser(oauth2Request("clientId", scopes("foo", "bar")), "name")); + UserInfo userInfo = userInfo("sub"); Set authScopes = scopes("foo", "bar", "baz"); - // this should fail with an error - assembler.assembleFrom(refreshToken, null , authScopes); + // when + Map result = assembler.assembleFrom(accessToken, userInfo, authScopes); + + + // then + Map expected = new ImmutableMap.Builder() + .put("sub", "sub") + .put("scope", "bar foo") + .put("active", Boolean.TRUE) + .put("user_id", "name") + .put("client_id", "clientId") + .put("token_type", "Bearer") + .build(); + + assertThat(result, is(not(equalTo(expected)))); } private UserInfo userInfo(String sub) { From 33b41af80627a10815214ab464c7ac92e78baf52 Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Tue, 24 Apr 2018 13:23:09 -0400 Subject: [PATCH 14/16] Update TestDefaultIntrospectionResultAssembler.java --- ...stDefaultIntrospectionResultAssembler.java | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java index d8d072798..0586ad40d 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java @@ -304,11 +304,11 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(equalTo(expected))); } - @Test(expected=ParseException.class) - public void testAssembleFrom_OAuth2AccessTokenEntityExpiration() { + @Test(expected= ParseException.class) + public void testAssembleFrom_OAuth2AccessTokenEntityExpiration() throws ParseException{ // given - OAuth2AccessTokenEntity accessToken = accessToken(null, scopes("foo", "bar"), null, "Bearer", + OAuth2AccessTokenEntity accessToken = accessToken(new Date(123 * 1000L), scopes("foo", "bar"), null, "Bearer", oauth2AuthenticationWithUser(oauth2Request("clientId"), "name")); UserInfo userInfo = userInfo("sub"); @@ -322,6 +322,7 @@ public class TestDefaultIntrospectionResultAssembler { // then Map expected = new ImmutableMap.Builder() .put("sub", "sub") + .put("exp",123L) .put("scope", "bar foo") .put("active", Boolean.TRUE) .put("user_id", "name") @@ -329,8 +330,45 @@ public class TestDefaultIntrospectionResultAssembler { .put("token_type", "Bearer") .build(); + + doThrow(ParseException.class).when(accessToken).getExpiration(); + accessToken.getExpiration(); + + //not reachable assertThat(result, is(not(equalTo(expected)))); } + + @Test(expected=ParseException.class) + public void testAssembleFrom_OAuth2RefreshTokenEntityExpiration() throws ParseException{ + + // given + OAuth2RefreshTokenEntity refreshToken = refreshToken(null, + oauth2AuthenticationWithUser(oauth2Request("clientId", scopes("foo", "bar")), "name")); + + UserInfo userInfo = userInfo("sub"); + + Set authScopes = scopes("foo", "bar", "baz"); + + // when + Map result = assembler.assembleFrom(refreshToken, userInfo, authScopes); + + + // then + Map expected = new ImmutableMap.Builder() + .put("sub", "sub") + .put("exp", 123L) + .put("scope", "bar foo") + .put("active", Boolean.TRUE) + .put("user_id", "name") + .put("client_id", "clientId") + .build(); + + doThrow(ParseException.class).when(refreshToken).getExpiration(); + refreshToken.getExpiration(); + + //not reachable + assertThat(result, is(not(equalTo(expected)))); + } private UserInfo userInfo(String sub) { UserInfo userInfo = mock(UserInfo.class); From 1d54151be9e02bc06aa91e5a23398e431a8569cd Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Tue, 24 Apr 2018 13:27:02 -0400 Subject: [PATCH 15/16] Update TestDefaultIntrospectionResultAssembler.java --- ...stDefaultIntrospectionResultAssembler.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java index 0586ad40d..790ff5e8d 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java @@ -37,13 +37,16 @@ import org.springframework.security.core.Authentication; import org.springframework.security.oauth2.provider.OAuth2Authentication; import org.springframework.security.oauth2.provider.OAuth2Request; + + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; - +import static org.hamcrest.CoreMatchers.not; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.junit.Assert.assertThat; @@ -176,6 +179,20 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(equalTo(expected))); } +// +// @Test(expected = ParseException.class) +// public void ABC() { +// +// // given +// OAuth2AccessTokenEntity accessToken = accessToken(new Date(123 * 1000L), scopes("foo", "bar"), null, "Bearer", +// oauth2AuthenticationWithUser(oauth2Request("clientId"), "name")); +// +// UserInfo userInfo = userInfo("sub"); +// +// Set authScopes = scopes("foo", "bar", "baz"); +// +// assembler.assembleFrom(accessToken, userInfo, authScopes);} +// @Test public void shouldAssembleExpectedResultForAccessTokenWithoutUserAuthentication() throws ParseException { @@ -304,6 +321,7 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(equalTo(expected))); } + @Test(expected= ParseException.class) public void testAssembleFrom_OAuth2AccessTokenEntityExpiration() throws ParseException{ @@ -370,6 +388,9 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(not(equalTo(expected)))); } + + + private UserInfo userInfo(String sub) { UserInfo userInfo = mock(UserInfo.class); given(userInfo.getSub()).willReturn(sub); From dbba32fda67e3334262ff1f3c89b8aad955ea65c Mon Sep 17 00:00:00 2001 From: Aishwarya Gosavi Date: Tue, 24 Apr 2018 14:16:00 -0400 Subject: [PATCH 16/16] Update TestDefaultIntrospectionResultAssembler.java --- .../TestDefaultIntrospectionResultAssembler.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java index 790ff5e8d..90436fe0c 100644 --- a/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java +++ b/openid-connect-server/src/test/java/org/mitre/oauth2/service/impl/TestDefaultIntrospectionResultAssembler.java @@ -179,20 +179,6 @@ public class TestDefaultIntrospectionResultAssembler { assertThat(result, is(equalTo(expected))); } -// -// @Test(expected = ParseException.class) -// public void ABC() { -// -// // given -// OAuth2AccessTokenEntity accessToken = accessToken(new Date(123 * 1000L), scopes("foo", "bar"), null, "Bearer", -// oauth2AuthenticationWithUser(oauth2Request("clientId"), "name")); -// -// UserInfo userInfo = userInfo("sub"); -// -// Set authScopes = scopes("foo", "bar", "baz"); -// -// assembler.assembleFrom(accessToken, userInfo, authScopes);} -// @Test public void shouldAssembleExpectedResultForAccessTokenWithoutUserAuthentication() throws ParseException { @@ -326,7 +312,7 @@ public class TestDefaultIntrospectionResultAssembler { public void testAssembleFrom_OAuth2AccessTokenEntityExpiration() throws ParseException{ // given - OAuth2AccessTokenEntity accessToken = accessToken(new Date(123 * 1000L), scopes("foo", "bar"), null, "Bearer", + OAuth2AccessTokenEntity accessToken = accessToken(null, scopes("foo", "bar"), null, "Bearer", oauth2AuthenticationWithUser(oauth2Request("clientId"), "name")); UserInfo userInfo = userInfo("sub");