Skip to content

Commit 2326592

Browse files
authored
Fix visibility on Firebase Functions (#6269)
1 parent d982626 commit 2326592

File tree

4 files changed

+112
-120
lines changed

4 files changed

+112
-120
lines changed

firebase-functions/api.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
package com.google.firebase.functions {
33

44
public final class FirebaseFunctions {
5-
method @NonNull public com.google.android.gms.tasks.Task<com.google.firebase.functions.HttpsCallableResult> call(@NonNull String name, @Nullable Object data, @NonNull com.google.firebase.functions.HttpsCallOptions options);
6-
method @NonNull public com.google.android.gms.tasks.Task<com.google.firebase.functions.HttpsCallableResult> call(@NonNull java.net.URL url, @Nullable Object data, @NonNull com.google.firebase.functions.HttpsCallOptions options);
75
method @NonNull public com.google.firebase.functions.HttpsCallableReference getHttpsCallable(@NonNull String name);
86
method @NonNull public com.google.firebase.functions.HttpsCallableReference getHttpsCallable(@NonNull String name, @NonNull com.google.firebase.functions.HttpsCallableOptions options);
97
method @NonNull public com.google.firebase.functions.HttpsCallableReference getHttpsCallableFromUrl(@NonNull java.net.URL url);
@@ -12,7 +10,6 @@ package com.google.firebase.functions {
1210
method @NonNull public static com.google.firebase.functions.FirebaseFunctions getInstance(@NonNull com.google.firebase.FirebaseApp app);
1311
method @NonNull public static com.google.firebase.functions.FirebaseFunctions getInstance(@NonNull String regionOrCustomDomain);
1412
method @NonNull public static com.google.firebase.functions.FirebaseFunctions getInstance();
15-
method @NonNull @VisibleForTesting public java.net.URL getURL(@NonNull String function);
1613
method public void useEmulator(@NonNull String host, int port);
1714
method @Deprecated public void useFunctionsEmulator(@NonNull String origin);
1815
field @NonNull public static final com.google.firebase.functions.FirebaseFunctions.Companion Companion;

firebase-functions/src/androidTest/java/com/google/firebase/functions/FirebaseFunctionsTest.java

Lines changed: 0 additions & 114 deletions
This file was deleted.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package com.google.firebase.functions
15+
16+
import androidx.test.platform.app.InstrumentationRegistry
17+
import androidx.test.runner.AndroidJUnit4
18+
import com.google.firebase.FirebaseApp
19+
import com.google.firebase.FirebaseOptions
20+
import com.google.firebase.functions.FirebaseFunctions.Companion.getInstance
21+
import junit.framework.TestCase.assertEquals
22+
import org.junit.Assert
23+
import org.junit.Test
24+
import org.junit.runner.RunWith
25+
26+
@RunWith(AndroidJUnit4::class)
27+
class FirebaseFunctionsTest {
28+
@Test
29+
fun testGetUrl() {
30+
val app = getApp("testGetUrl")
31+
var functions = getInstance(app, "my-region")
32+
var url = functions.getURL("my-endpoint")
33+
assertEquals("https://my-region-my-project.cloudfunctions.net/my-endpoint", url.toString())
34+
35+
functions = getInstance(app)
36+
url = functions.getURL("my-endpoint")
37+
assertEquals("https://us-central1-my-project.cloudfunctions.net/my-endpoint", url.toString())
38+
39+
functions = getInstance(app, "https://mydomain.com")
40+
url = functions.getURL("my-endpoint")
41+
Assert.assertEquals("https://mydomain.com/my-endpoint", url.toString())
42+
43+
functions = getInstance(app, "https://mydomain.com/foo")
44+
url = functions.getURL("my-endpoint")
45+
assertEquals("https://mydomain.com/foo/my-endpoint", url.toString())
46+
}
47+
48+
@Test
49+
fun testGetUrl_withEmulator() {
50+
val app = getApp("testGetUrl_withEmulator")
51+
val functions = getInstance(app)
52+
functions.useEmulator("10.0.2.2", 5001)
53+
val functionsWithoutRegion = getInstance(app)
54+
val withoutRegion = functionsWithoutRegion.getURL("my-endpoint")
55+
assertEquals(
56+
"http://10.0.2.2:5001/my-project/us-central1/my-endpoint",
57+
withoutRegion.toString()
58+
)
59+
60+
val functionsWithRegion = getInstance(app, "my-region")
61+
functionsWithRegion.useEmulator("10.0.2.2", 5001)
62+
val withRegion = functionsWithRegion.getURL("my-endpoint")
63+
assertEquals("http://10.0.2.2:5001/my-project/my-region/my-endpoint", withRegion.toString())
64+
65+
val functionsWithCustomDomain = getInstance(app, "https://mydomain.com")
66+
functionsWithCustomDomain.useEmulator("10.0.2.2", 5001)
67+
val withCustomDOmain = functionsWithCustomDomain.getURL("my-endpoint")
68+
assertEquals(
69+
"http://10.0.2.2:5001/my-project/us-central1/my-endpoint",
70+
withCustomDOmain.toString()
71+
)
72+
}
73+
74+
@Test
75+
fun testGetUrl_withEmulator_matchesOldImpl() {
76+
val app = getApp("testGetUrl_withEmulator_matchesOldImpl")
77+
val functions = getInstance(app)
78+
functions.useEmulator("10.0.2.2", 5001)
79+
val newImplUrl = functions.getURL("my-endpoint")
80+
functions.useFunctionsEmulator("http://10.0.2.2:5001")
81+
val oldImplUrl = functions.getURL("my-endpoint")
82+
assertEquals(newImplUrl.toString(), oldImplUrl.toString())
83+
}
84+
85+
@Test
86+
fun testEmulatorSettings() {
87+
val app = getApp("testEmulatorSettings")
88+
val functions1 = getInstance(app)
89+
functions1.useEmulator("10.0.2.2", 5001)
90+
val functions2 = getInstance(app)
91+
assertEquals(functions1.getURL("foo").toString(), functions2.getURL("foo").toString())
92+
}
93+
94+
private fun getApp(name: String): FirebaseApp {
95+
return FirebaseApp.initializeApp(
96+
InstrumentationRegistry.getInstrumentation().targetContext,
97+
FirebaseOptions.Builder()
98+
.setProjectId("my-project")
99+
.setApplicationId("appid")
100+
.setApiKey("apikey")
101+
.build(),
102+
name
103+
)
104+
}
105+
}

firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ internal constructor(
131131
* @return The URL.
132132
*/
133133
@VisibleForTesting
134-
fun getURL(function: String): URL {
134+
internal fun getURL(function: String): URL {
135135
val emulatorSettings = emulatorSettings
136136
if (emulatorSettings != null) {
137137
urlFormat =
@@ -173,7 +173,11 @@ internal constructor(
173173
* @param data Parameters to pass to the function. Can be anything encodable as JSON.
174174
* @return A Task that will be completed when the request is complete.
175175
*/
176-
fun call(name: String, data: Any?, options: HttpsCallOptions): Task<HttpsCallableResult> {
176+
internal fun call(
177+
name: String,
178+
data: Any?,
179+
options: HttpsCallOptions
180+
): Task<HttpsCallableResult> {
177181
return providerInstalled.task
178182
.continueWithTask(executor) { task: Task<Void>? ->
179183
contextProvider.getContext(options.limitedUseAppCheckTokens)
@@ -195,7 +199,7 @@ internal constructor(
195199
* @param data Parameters to pass to the function. Can be anything encodable as JSON.
196200
* @return A Task that will be completed when the request is complete.
197201
*/
198-
fun call(url: URL, data: Any?, options: HttpsCallOptions): Task<HttpsCallableResult> {
202+
internal fun call(url: URL, data: Any?, options: HttpsCallOptions): Task<HttpsCallableResult> {
199203
return providerInstalled.task
200204
.continueWithTask(executor) { task: Task<Void>? ->
201205
contextProvider.getContext(options.limitedUseAppCheckTokens)

0 commit comments

Comments
 (0)