Skip to content

Commit 907c495

Browse files
committed
Clean up prefix checks and move testing to API level.
1 parent 810eb4b commit 907c495

File tree

6 files changed

+101
-61
lines changed

6 files changed

+101
-61
lines changed

src/main/java/com/google/firebase/auth/OidcProviderConfig.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ public static final class CreateRequest extends AbstractCreateRequest<CreateRequ
7777
*/
7878
public CreateRequest() { }
7979

80+
/**
81+
* Sets the ID for the new provider.
82+
*
83+
* @param providerId A non-null, non-empty provider ID string.
84+
* @throws IllegalArgumentException If the provider ID is null or empty, or is not prefixed with
85+
* 'oidc.'.
86+
*/
87+
@Override
88+
public CreateRequest setProviderId(String providerId) {
89+
checkOidcProviderId(providerId);
90+
return super.setProviderId(providerId);
91+
}
92+
8093
/**
8194
* Sets the client ID for the new provider.
8295
*
@@ -106,10 +119,6 @@ public CreateRequest setIssuer(String issuer) {
106119
CreateRequest getThis() {
107120
return this;
108121
}
109-
110-
void assertValidProviderIdFormat(String providerId) {
111-
checkOidcProviderId(providerId);
112-
}
113122
}
114123

115124
/**

src/main/java/com/google/firebase/auth/ProviderConfig.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,7 @@ public abstract static class AbstractCreateRequest<T extends AbstractCreateReque
7171
final Map<String,Object> properties = new HashMap<>();
7272
String providerId;
7373

74-
/**
75-
* Sets the ID for the new provider.
76-
*
77-
* @param providerId A non-null, non-empty provider ID string.
78-
* @throws IllegalArgumentException If the provider ID is null or empty, or if the format is
79-
* invalid.
80-
*/
81-
public T setProviderId(String providerId) {
82-
checkArgument(
83-
!Strings.isNullOrEmpty(providerId), "Provider ID name must not be null or empty.");
84-
assertValidProviderIdFormat(providerId);
74+
T setProviderId(String providerId) {
8575
this.providerId = providerId;
8676
return getThis();
8777
}
@@ -117,8 +107,6 @@ Map<String, Object> getProperties() {
117107
}
118108

119109
abstract T getThis();
120-
121-
abstract void assertValidProviderIdFormat(String providerId);
122110
}
123111

124112
/**

src/main/java/com/google/firebase/auth/SamlProviderConfig.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,19 @@ public static final class CreateRequest extends AbstractCreateRequest<CreateRequ
112112
*/
113113
public CreateRequest() { }
114114

115+
/**
116+
* Sets the ID for the new provider.
117+
*
118+
* @param providerId A non-null, non-empty provider ID string.
119+
* @throws IllegalArgumentException If the provider ID is null or empty, or is not prefixed with
120+
* 'saml.'.
121+
*/
122+
@Override
123+
public CreateRequest setProviderId(String providerId) {
124+
checkSamlProviderId(providerId);
125+
return super.setProviderId(providerId);
126+
}
127+
115128
/**
116129
* Sets the IDP entity ID for the new provider.
117130
*
@@ -187,9 +200,5 @@ public CreateRequest setCallbackUrl(String callbackUrl) {
187200
CreateRequest getThis() {
188201
return this;
189202
}
190-
191-
void assertValidProviderIdFormat(String providerId) {
192-
checkSamlProviderId(providerId);
193-
}
194203
}
195204
}

src/test/java/com/google/firebase/auth/FirebaseUserManagerTest.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,32 @@ public void testGetOidcProviderConfig() throws Exception {
16061606
checkUrl(interceptor, "GET", PROJECT_BASE_URL + "/oauthIdpConfigs/oidc.provider-id");
16071607
}
16081608

1609+
@Test
1610+
public void testGetOidcProviderConfigMissingId() throws Exception {
1611+
TestResponseInterceptor interceptor = initializeAppForUserManagement(
1612+
TestUtils.loadResource("oidc.json"));
1613+
1614+
try {
1615+
FirebaseAuth.getInstance().getOidcProviderConfig(null);
1616+
fail("No error thrown for missing provider ID.");
1617+
} catch (IllegalArgumentException e) {
1618+
// Expected.
1619+
}
1620+
}
1621+
1622+
@Test
1623+
public void testGetOidcProviderConfigInvalidId() throws Exception {
1624+
TestResponseInterceptor interceptor = initializeAppForUserManagement(
1625+
TestUtils.loadResource("oidc.json"));
1626+
1627+
try {
1628+
FirebaseAuth.getInstance().getOidcProviderConfig("not a valid provider ID");
1629+
fail("No error thrown for invalid provider ID.");
1630+
} catch (IllegalArgumentException e) {
1631+
// Expected.
1632+
}
1633+
}
1634+
16091635
@Test
16101636
public void testGetOidcProviderConfigWithNotFoundError() throws Exception {
16111637
TestResponseInterceptor interceptor =
@@ -1715,6 +1741,30 @@ public void testDeleteOidcProviderConfig() throws Exception {
17151741
checkUrl(interceptor, "DELETE", PROJECT_BASE_URL + "/oauthIdpConfigs/oidc.provider-id");
17161742
}
17171743

1744+
@Test
1745+
public void testDeleteOidcProviderMissingId() throws Exception {
1746+
TestResponseInterceptor interceptor = initializeAppForUserManagement("{}");
1747+
1748+
try {
1749+
FirebaseAuth.getInstance().deleteOidcProviderConfig(null);
1750+
fail("No error thrown for missing provider ID.");
1751+
} catch (IllegalArgumentException e) {
1752+
// Expected.
1753+
}
1754+
}
1755+
1756+
@Test
1757+
public void testDeleteOidcProviderInvalidId() throws Exception {
1758+
TestResponseInterceptor interceptor = initializeAppForUserManagement("{}");
1759+
1760+
try {
1761+
FirebaseAuth.getInstance().deleteOidcProviderConfig("not a valid provider ID");
1762+
fail("No error thrown for invalid provider ID.");
1763+
} catch (IllegalArgumentException e) {
1764+
// Expected.
1765+
}
1766+
}
1767+
17181768
@Test
17191769
public void testDeleteOidcProviderConfigWithNotFoundError() throws Exception {
17201770
TestResponseInterceptor interceptor =
@@ -1904,6 +1954,30 @@ public void testDeleteSamlProviderConfig() throws Exception {
19041954
checkUrl(interceptor, "DELETE", PROJECT_BASE_URL + "/inboundSamlConfigs/saml.provider-id");
19051955
}
19061956

1957+
@Test
1958+
public void testDeleteSamlProviderMissingId() throws Exception {
1959+
TestResponseInterceptor interceptor = initializeAppForUserManagement("{}");
1960+
1961+
try {
1962+
FirebaseAuth.getInstance().deleteSamlProviderConfig(null);
1963+
fail("No error thrown for missing provider ID.");
1964+
} catch (IllegalArgumentException e) {
1965+
// Expected.
1966+
}
1967+
}
1968+
1969+
@Test
1970+
public void testDeleteSamlProviderInvalidId() throws Exception {
1971+
TestResponseInterceptor interceptor = initializeAppForUserManagement("{}");
1972+
1973+
try {
1974+
FirebaseAuth.getInstance().deleteSamlProviderConfig("not a valid provider ID");
1975+
fail("No error thrown for invalid provider ID.");
1976+
} catch (IllegalArgumentException e) {
1977+
// Expected.
1978+
}
1979+
}
1980+
19071981
@Test
19081982
public void testDeleteSamlProviderConfigWithNotFoundError() throws Exception {
19091983
TestResponseInterceptor interceptor =

src/test/java/com/google/firebase/auth/OidcProviderConfigTest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,6 @@ public void testJsonDeserialization() throws IOException {
5151
assertEquals("https://oidc.com/issuer", config.getIssuer());
5252
}
5353

54-
@Test
55-
public void testCheckOidcProviderId() {
56-
OidcProviderConfig.checkOidcProviderId("oidc.valid-id");
57-
}
58-
59-
@Test(expected = IllegalArgumentException.class)
60-
public void testCreateOidcProviderIdNull() {
61-
OidcProviderConfig.checkOidcProviderId(null);
62-
}
63-
64-
@Test(expected = IllegalArgumentException.class)
65-
public void testCreateOidcProviderIdEmpty() {
66-
OidcProviderConfig.checkOidcProviderId("");
67-
}
68-
69-
@Test(expected = IllegalArgumentException.class)
70-
public void testCreateOidcProviderIdInvalidPrefix() {
71-
OidcProviderConfig.checkOidcProviderId("not prefixed with oidc.");
72-
}
73-
7454
@Test
7555
public void testCreateRequest() throws IOException {
7656
OidcProviderConfig.CreateRequest createRequest = new OidcProviderConfig.CreateRequest();

src/test/java/com/google/firebase/auth/SamlProviderConfigTest.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,6 @@ public void testJsonDeserialization() throws IOException {
6868
assertEquals("https://projectId.firebaseapp.com/__/auth/handler", config.getCallbackUrl());
6969
}
7070

71-
@Test
72-
public void testCheckSamlProviderId() {
73-
SamlProviderConfig.checkSamlProviderId("saml.valid-id");
74-
}
75-
76-
@Test(expected = IllegalArgumentException.class)
77-
public void testCreateSamlProviderIdNull() {
78-
SamlProviderConfig.checkSamlProviderId(null);
79-
}
80-
81-
@Test(expected = IllegalArgumentException.class)
82-
public void testCreateSamlProviderIdEmpty() {
83-
SamlProviderConfig.checkSamlProviderId("");
84-
}
85-
86-
@Test(expected = IllegalArgumentException.class)
87-
public void testCreateSamlProviderIdInvalidPrefix() {
88-
SamlProviderConfig.checkSamlProviderId("not prefixed with saml.");
89-
}
90-
9171
@Test
9272
public void testCreateRequest() throws IOException {
9373
SamlProviderConfig.CreateRequest createRequest =

0 commit comments

Comments
 (0)