From 4aac664285d9bf6193ef7a654f5d1a4b85a4e6cf Mon Sep 17 00:00:00 2001 From: Emily Ploszaj Date: Fri, 8 Nov 2024 15:44:32 -0600 Subject: [PATCH 1/5] Adjust Functions Kotlin docs for release --- .../firebase/functions/FirebaseFunctions.kt | 2 +- .../functions/FirebaseFunctionsException.kt | 20 +++++++++---------- .../firebase/functions/HttpsCallOptions.kt | 14 ++++++------- .../functions/HttpsCallableOptions.kt | 2 +- .../functions/HttpsCallableReference.kt | 6 +++--- .../firebase/functions/HttpsCallableResult.kt | 6 +++--- .../google/firebase/functions/Serializer.kt | 12 +++++------ 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.kt b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.kt index 3f5fe5d63d9..e13453e7f7d 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctions.kt @@ -151,7 +151,7 @@ internal constructor( } } - @Deprecated("Use {@link #useEmulator(String, int)} to connect to the emulator. ") + @Deprecated("Use useEmulator to connect to the emulator.") public fun useFunctionsEmulator(origin: String) { Preconditions.checkNotNull(origin, "origin cannot be null") urlFormat = "$origin/%2\$s/%1\$s/%3\$s" diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt index 1d8653a521c..ab41ba28673 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt @@ -29,8 +29,8 @@ public class FirebaseFunctionsException : FirebaseException { */ public enum class Code(private val value: Int) { /** - * The operation completed successfully. FirebaseFunctionsException will never have a status of - * OK. + * The operation completed successfully. `FirebaseFunctionsException` will never have a status of + * `OK`. */ OK(0), @@ -41,9 +41,9 @@ public class FirebaseFunctionsException : FirebaseException { UNKNOWN(2), /** - * Client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. - * INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the - * system (e.g., an invalid field name). + * Client specified an invalid argument. Note that this differs from `FAILED_PRECONDITION`. + * `INVALID_ARGUMENT` indicates arguments that are problematic regardless of the state of the + * system (For example, an invalid field name). */ INVALID_ARGUMENT(3), @@ -126,12 +126,12 @@ public class FirebaseFunctionsException : FirebaseException { } /** - * Takes an HTTP status code and returns the corresponding FUNErrorCode error code. This is + * Takes an HTTP status code and returns the corresponding [Code] error code. This is * the standard HTTP status code -> error mapping defined in: * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto * * @param status An HTTP status code. - * @return The corresponding Code, or Code.UNKNOWN if none. + * @return The corresponding `Code`, or `Code.UNKNOWN` if none. */ @JvmStatic public fun fromHttpStatus(status: Int): Code { @@ -157,7 +157,7 @@ public class FirebaseFunctionsException : FirebaseException { /** * Gets the error code for the operation that failed. * - * @return the code for the FirebaseFunctionsException + * @return the code for the `FirebaseFunctionsException` */ public val code: Code @@ -183,7 +183,7 @@ public class FirebaseFunctionsException : FirebaseException { this.details = details } - public companion object { + internal companion object { /** * Takes an HTTP response and returns the corresponding Exception if any. * @@ -193,7 +193,7 @@ public class FirebaseFunctionsException : FirebaseException { * @return The corresponding Exception, or null if none. */ @JvmStatic - public fun fromResponse( + internal fun fromResponse( code: Code, body: String?, serializer: Serializer diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallOptions.kt b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallOptions.kt index 6e36efffe18..f6b0e3f07c3 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallOptions.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallOptions.kt @@ -17,22 +17,22 @@ import java.util.concurrent.TimeUnit import okhttp3.OkHttpClient /** An internal class for keeping track of options applied to an HttpsCallableReference. */ -public class HttpsCallOptions { +internal class HttpsCallOptions { // The timeout to use for calls from references created by this Functions. private var timeout = DEFAULT_TIMEOUT private var timeoutUnits = DEFAULT_TIMEOUT_UNITS @JvmField public val limitedUseAppCheckTokens: Boolean /** Creates an (internal) HttpsCallOptions from the (external) [HttpsCallableOptions]. */ - public constructor(publicCallableOptions: HttpsCallableOptions) { + internal constructor(publicCallableOptions: HttpsCallableOptions) { limitedUseAppCheckTokens = publicCallableOptions.limitedUseAppCheckTokens } - public constructor() { + internal constructor() { limitedUseAppCheckTokens = false } - public fun getLimitedUseAppCheckTokens(): Boolean { + internal fun getLimitedUseAppCheckTokens(): Boolean { return limitedUseAppCheckTokens } @@ -42,7 +42,7 @@ public class HttpsCallOptions { * @param timeout The length of the timeout, in the given units. * @param units The units for the specified timeout. */ - public fun setTimeout(timeout: Long, units: TimeUnit) { + internal fun setTimeout(timeout: Long, units: TimeUnit) { this.timeout = timeout timeoutUnits = units } @@ -52,12 +52,12 @@ public class HttpsCallOptions { * * @return The timeout, in milliseconds. */ - public fun getTimeout(): Long { + internal fun getTimeout(): Long { return timeoutUnits.toMillis(timeout) } /** Creates a new OkHttpClient with these options applied to it. */ - public fun apply(client: OkHttpClient): OkHttpClient { + internal fun apply(client: OkHttpClient): OkHttpClient { return client .newBuilder() .callTimeout(timeout, timeoutUnits) diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableOptions.kt b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableOptions.kt index 32b05afded2..63aa4547e64 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableOptions.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableOptions.kt @@ -31,7 +31,7 @@ private constructor( return limitedUseAppCheckTokens } - /** Builder class for [com.google.firebase.functions.HttpsCallableOptions] */ + /** A builder for creating [com.google.firebase.functions.HttpsCallableOptions]. */ public class Builder { @JvmField public var limitedUseAppCheckTokens: Boolean = false diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.kt b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.kt index 90bdb63221b..88db9db4ee4 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.kt @@ -32,7 +32,7 @@ public class HttpsCallableReference { private val url: URL? // Options for how to do the HTTPS call. - @VisibleForTesting public val options: HttpsCallOptions + @VisibleForTesting internal val options: HttpsCallOptions /** Creates a new reference with the given options. */ internal constructor( @@ -81,7 +81,7 @@ public class HttpsCallableReference { * Auth, an auth token for the user will also be automatically included. * * Firebase Instance ID sends data to the Firebase backend periodically to collect information - * regarding the app instance. To stop this, see [ ] + * regarding the app instance. To stop this, see * [com.google.firebase.iid.FirebaseInstanceId.deleteInstanceId]. It will resume with a new * Instance ID the next time you call this method. * @@ -111,7 +111,7 @@ public class HttpsCallableReference { * Auth, an auth token for the user will also be automatically included. * * Firebase Instance ID sends data to the Firebase backend periodically to collect information - * regarding the app instance. To stop this, see [ ] + * regarding the app instance. To stop this, see * [com.google.firebase.iid.FirebaseInstanceId.deleteInstanceId]. It will resume with a new * Instance ID the next time you call this method. * diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt index ddda0ea57bb..ed90a1d45ce 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt @@ -13,7 +13,7 @@ // limitations under the License. package com.google.firebase.functions -/** The result of calling a HttpsCallableReference function. */ +/** The result of calling a `HttpsCallableReference` function. */ public class HttpsCallableResult internal constructor( // The actual result data, as generic types decoded from JSON. private val data: Any?) { @@ -21,8 +21,8 @@ private val data: Any?) { * Returns the data that was returned from the Callable HTTPS trigger. * * The data is in the form of native Java objects. For example, if your trigger returned an array, - * this object would be a List. If your trigger returned a JavaScript object with keys and - * values, this object would be a Map. + * this object would be a `List`. If your trigger returned a JavaScript object with keys and + * values, this object would be a `Map`. */ public fun getData(): Any? { return data diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt b/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt index fac34490845..d4873a58f98 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt @@ -23,7 +23,7 @@ import org.json.JSONException import org.json.JSONObject /** Converts raw Java types into JSON objects. */ -public class Serializer { +internal class Serializer { private val dateFormat: DateFormat init { @@ -32,7 +32,7 @@ public class Serializer { dateFormat.timeZone = TimeZone.getTimeZone("UTC") } - public fun encode(obj: Any?): Any { + internal fun encode(obj: Any?): Any { if (obj == null || obj === JSONObject.NULL) { return JSONObject.NULL } @@ -113,7 +113,7 @@ public class Serializer { throw IllegalArgumentException("Object cannot be encoded in JSON: $obj") } - public fun decode(obj: Any): Any? { + internal fun decode(obj: Any): Any? { // TODO: Maybe this should throw a FirebaseFunctionsException instead? if (obj is Number) { return obj @@ -170,11 +170,11 @@ public class Serializer { throw IllegalArgumentException("Object cannot be decoded from JSON: $obj") } - public companion object { + internal companion object { @VisibleForTesting - public const val LONG_TYPE: String = "type.googleapis.com/google.protobuf.Int64Value" + internal const val LONG_TYPE: String = "type.googleapis.com/google.protobuf.Int64Value" @VisibleForTesting - public const val UNSIGNED_LONG_TYPE: String = "type.googleapis.com/google.protobuf.UInt64Value" + internal const val UNSIGNED_LONG_TYPE: String = "type.googleapis.com/google.protobuf.UInt64Value" } } From 0618642fc07dade34da5785c5a8b1986a51314ee Mon Sep 17 00:00:00 2001 From: Emily Ploszaj Date: Fri, 8 Nov 2024 15:46:00 -0600 Subject: [PATCH 2/5] Format --- .../firebase/functions/FirebaseFunctionsException.kt | 8 ++++---- .../com/google/firebase/functions/HttpsCallableResult.kt | 4 ++-- .../main/java/com/google/firebase/functions/Serializer.kt | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt index ab41ba28673..1ac56639bf4 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/FirebaseFunctionsException.kt @@ -29,8 +29,8 @@ public class FirebaseFunctionsException : FirebaseException { */ public enum class Code(private val value: Int) { /** - * The operation completed successfully. `FirebaseFunctionsException` will never have a status of - * `OK`. + * The operation completed successfully. `FirebaseFunctionsException` will never have a status + * of `OK`. */ OK(0), @@ -126,8 +126,8 @@ public class FirebaseFunctionsException : FirebaseException { } /** - * Takes an HTTP status code and returns the corresponding [Code] error code. This is - * the standard HTTP status code -> error mapping defined in: + * Takes an HTTP status code and returns the corresponding [Code] error code. This is the + * standard HTTP status code -> error mapping defined in: * https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto * * @param status An HTTP status code. diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt index ed90a1d45ce..c75d584b2c6 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableResult.kt @@ -21,8 +21,8 @@ private val data: Any?) { * Returns the data that was returned from the Callable HTTPS trigger. * * The data is in the form of native Java objects. For example, if your trigger returned an array, - * this object would be a `List`. If your trigger returned a JavaScript object with keys and - * values, this object would be a `Map`. + * this object would be a `List`. If your trigger returned a JavaScript object with keys + * and values, this object would be a `Map`. */ public fun getData(): Any? { return data diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt b/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt index d4873a58f98..1d6fd2cc189 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt @@ -175,6 +175,7 @@ internal class Serializer { internal const val LONG_TYPE: String = "type.googleapis.com/google.protobuf.Int64Value" @VisibleForTesting - internal const val UNSIGNED_LONG_TYPE: String = "type.googleapis.com/google.protobuf.UInt64Value" + internal const val UNSIGNED_LONG_TYPE: String = + "type.googleapis.com/google.protobuf.UInt64Value" } } From a4ce74052dab2158c9fc60237272de1c256ffa1c Mon Sep 17 00:00:00 2001 From: Emily Ploszaj Date: Fri, 27 Dec 2024 11:01:01 -0600 Subject: [PATCH 3/5] Update api.txt --- firebase-functions/api.txt | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/firebase-functions/api.txt b/firebase-functions/api.txt index 323ba72e22f..2963a38621f 100644 --- a/firebase-functions/api.txt +++ b/firebase-functions/api.txt @@ -23,12 +23,10 @@ package com.google.firebase.functions { } public final class FirebaseFunctionsException extends com.google.firebase.FirebaseException { - method @Nullable public static com.google.firebase.functions.FirebaseFunctionsException fromResponse(@NonNull com.google.firebase.functions.FirebaseFunctionsException.Code code, @Nullable String body, @NonNull com.google.firebase.functions.Serializer serializer); method @NonNull public com.google.firebase.functions.FirebaseFunctionsException.Code getCode(); method @Nullable public Object getDetails(); property @NonNull public final com.google.firebase.functions.FirebaseFunctionsException.Code code; property @Nullable public final Object details; - field @NonNull public static final com.google.firebase.functions.FirebaseFunctionsException.Companion Companion; } public enum FirebaseFunctionsException.Code { @@ -61,10 +59,6 @@ package com.google.firebase.functions { method @NonNull public com.google.firebase.functions.FirebaseFunctionsException.Code fromValue(int value); } - public static final class FirebaseFunctionsException.Companion { - method @Nullable public com.google.firebase.functions.FirebaseFunctionsException fromResponse(@NonNull com.google.firebase.functions.FirebaseFunctionsException.Code code, @Nullable String body, @NonNull com.google.firebase.functions.Serializer serializer); - } - public final class FunctionsKt { method @NonNull public static com.google.firebase.functions.FirebaseFunctions functions(@NonNull com.google.firebase.Firebase, @NonNull String regionOrCustomDomain); method @NonNull public static com.google.firebase.functions.FirebaseFunctions functions(@NonNull com.google.firebase.Firebase, @NonNull com.google.firebase.FirebaseApp app); @@ -74,16 +68,6 @@ package com.google.firebase.functions { method @NonNull public static com.google.firebase.functions.HttpsCallableReference getHttpsCallableFromUrl(@NonNull com.google.firebase.functions.FirebaseFunctions, @NonNull java.net.URL url, @NonNull kotlin.jvm.functions.Function1 init); } - public final class HttpsCallOptions { - ctor public HttpsCallOptions(@NonNull com.google.firebase.functions.HttpsCallableOptions publicCallableOptions); - ctor public HttpsCallOptions(); - method @NonNull public okhttp3.OkHttpClient apply(@NonNull okhttp3.OkHttpClient client); - method public boolean getLimitedUseAppCheckTokens(); - method public long getTimeout(); - method public void setTimeout(long timeout, @NonNull java.util.concurrent.TimeUnit units); - field public final boolean limitedUseAppCheckTokens; - } - public final class HttpsCallableOptions { method public boolean getLimitedUseAppCheckTokens(); field public final boolean limitedUseAppCheckTokens; @@ -100,11 +84,9 @@ package com.google.firebase.functions { public final class HttpsCallableReference { method @NonNull public com.google.android.gms.tasks.Task call(@Nullable Object data); method @NonNull public com.google.android.gms.tasks.Task call(); - method @NonNull public com.google.firebase.functions.HttpsCallOptions getOptions(); method public long getTimeout(); method public void setTimeout(long timeout, @NonNull java.util.concurrent.TimeUnit units); method @NonNull public com.google.firebase.functions.HttpsCallableReference withTimeout(long timeout, @NonNull java.util.concurrent.TimeUnit units); - property @NonNull public final com.google.firebase.functions.HttpsCallOptions options; property public final long timeout; } @@ -113,18 +95,6 @@ package com.google.firebase.functions { field @Nullable public final Object data; } - public final class Serializer { - ctor public Serializer(); - method @Nullable public Object decode(@NonNull Object obj); - method @NonNull public Object encode(@Nullable Object obj); - field @NonNull public static final com.google.firebase.functions.Serializer.Companion Companion; - field @NonNull @VisibleForTesting public static final String LONG_TYPE = "type.googleapis.com/google.protobuf.Int64Value"; - field @NonNull @VisibleForTesting public static final String UNSIGNED_LONG_TYPE = "type.googleapis.com/google.protobuf.UInt64Value"; - } - - public static final class Serializer.Companion { - } - } package com.google.firebase.functions.ktx { From 511209fd9e3314a0cce6fd71dd1dd1e548a727db Mon Sep 17 00:00:00 2001 From: Emily Ploszaj Date: Fri, 27 Dec 2024 14:11:16 -0600 Subject: [PATCH 4/5] Remove duplicate ktx tests --- .../firebase/functions/ktx/CallTests.kt | 93 ----------- .../firebase/functions/TestVisibilityUtil.kt | 22 --- .../firebase/functions/ktx/FunctionsTests.kt | 153 ------------------ 3 files changed, 268 deletions(-) delete mode 100644 firebase-functions/ktx/src/androidTest/kotlin/com/google/firebase/functions/ktx/CallTests.kt delete mode 100644 firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/TestVisibilityUtil.kt delete mode 100644 firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/ktx/FunctionsTests.kt diff --git a/firebase-functions/ktx/src/androidTest/kotlin/com/google/firebase/functions/ktx/CallTests.kt b/firebase-functions/ktx/src/androidTest/kotlin/com/google/firebase/functions/ktx/CallTests.kt deleted file mode 100644 index 87ca19f8348..00000000000 --- a/firebase-functions/ktx/src/androidTest/kotlin/com/google/firebase/functions/ktx/CallTests.kt +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * 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. - */ - -package com.google.firebase.functions.ktx - -import androidx.test.InstrumentationRegistry -import androidx.test.runner.AndroidJUnit4 -import com.google.android.gms.tasks.Tasks -import com.google.common.truth.Truth.assertThat -import com.google.firebase.FirebaseApp -import com.google.firebase.ktx.Firebase -import com.google.firebase.ktx.app -import com.google.firebase.ktx.initialize -import org.junit.AfterClass -import org.junit.BeforeClass -import org.junit.Test -import org.junit.runner.RunWith - -const val APP_ID = "APP_ID" -const val API_KEY = "API_KEY" - -@RunWith(AndroidJUnit4::class) -class CallTests { - companion object { - lateinit var app: FirebaseApp - - @BeforeClass - @JvmStatic - fun setup() { - app = Firebase.initialize(InstrumentationRegistry.getContext())!! - } - - @AfterClass - @JvmStatic - fun cleanup() { - app.delete() - } - } - - @Test - fun testDataCall() { - val functions = Firebase.functions(app) - val input = - hashMapOf( - "bool" to true, - "int" to 2, - "long" to 3L, - "string" to "four", - "array" to listOf(5, 6), - "null" to null - ) - - var function = functions.getHttpsCallable("dataTest") - val actual = Tasks.await(function.call(input)).getData() - - assertThat(actual).isInstanceOf(Map::class.java) - @Suppress("UNCHECKED_CAST") val map = actual as Map - assertThat(map["message"]).isEqualTo("stub response") - assertThat(map["code"]).isEqualTo(42) - assertThat(map["long"]).isEqualTo(420L) - } - - @Test - fun testNullDataCall() { - val functions = Firebase.functions(app) - var function = functions.getHttpsCallable("nullTest") - val actual = Tasks.await(function.call(null)).getData() - - assertThat(actual).isNull() - } - - @Test - fun testEmptyDataCall() { - val functions = Firebase.functions(app) - var function = functions.getHttpsCallable("nullTest") - val actual = Tasks.await(function.call()).getData() - - assertThat(actual).isNull() - } -} diff --git a/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/TestVisibilityUtil.kt b/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/TestVisibilityUtil.kt deleted file mode 100644 index 9a8be4b4f9c..00000000000 --- a/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/TestVisibilityUtil.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * 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. - */ - -package com.google.firebase.functions - -/** - * Returns true if the {@link HttpsCallableReference} is configured to use FAC limited-use tokens. - */ -fun HttpsCallableReference.usesLimitedUseFacTokens() = options.getLimitedUseAppCheckTokens() diff --git a/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/ktx/FunctionsTests.kt b/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/ktx/FunctionsTests.kt deleted file mode 100644 index 34e845c7927..00000000000 --- a/firebase-functions/ktx/src/test/kotlin/com/google/firebase/functions/ktx/FunctionsTests.kt +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2019 Google LLC - * - * 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. - */ - -package com.google.firebase.functions.ktx - -import androidx.test.core.app.ApplicationProvider -import com.google.common.truth.Truth.assertThat -import com.google.firebase.FirebaseApp -import com.google.firebase.FirebaseOptions -import com.google.firebase.functions.FirebaseFunctions -import com.google.firebase.functions.usesLimitedUseFacTokens -import com.google.firebase.ktx.Firebase -import com.google.firebase.ktx.app -import com.google.firebase.ktx.initialize -import com.google.firebase.platforminfo.UserAgentPublisher -import java.net.URL -import org.junit.After -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner - -const val APP_ID = "APP_ID" -const val API_KEY = "API_KEY" - -const val EXISTING_APP = "existing" - -abstract class BaseTestCase { - @Before - fun setUp() { - Firebase.initialize( - ApplicationProvider.getApplicationContext(), - FirebaseOptions.Builder() - .setApplicationId(APP_ID) - .setApiKey(API_KEY) - .setProjectId("123") - .build() - ) - - Firebase.initialize( - ApplicationProvider.getApplicationContext(), - FirebaseOptions.Builder() - .setApplicationId(APP_ID) - .setApiKey(API_KEY) - .setProjectId("123") - .build(), - EXISTING_APP - ) - } - - @After - fun cleanUp() { - FirebaseApp.clearInstancesForTest() - } -} - -@RunWith(RobolectricTestRunner::class) -class FunctionsTests : BaseTestCase() { - - @Test - fun `functions should delegate to FirebaseFunctions#getInstance()`() { - assertThat(Firebase.functions).isSameInstanceAs(FirebaseFunctions.getInstance()) - } - - @Test - fun `FirebaseApp#functions should delegate to FirebaseFunctions#getInstance(FirebaseApp)`() { - val app = Firebase.app(EXISTING_APP) - assertThat(Firebase.functions(app)).isSameInstanceAs(FirebaseFunctions.getInstance(app)) - } - - @Test - fun `Firebase#functions should delegate to FirebaseFunctions#getInstance(region)`() { - val region = "valid_region" - assertThat(Firebase.functions(region)).isSameInstanceAs(FirebaseFunctions.getInstance(region)) - } - - @Test - fun `Firebase#functions should delegate to FirebaseFunctions#getInstance(FirebaseApp, region)`() { - val app = Firebase.app(EXISTING_APP) - val region = "valid_region" - assertThat(Firebase.functions(app, region)) - .isSameInstanceAs(FirebaseFunctions.getInstance(app, region)) - } -} - -@RunWith(RobolectricTestRunner::class) -class LibraryVersionTest : BaseTestCase() { - @Test - fun `library version should be registered with runtime`() { - val publisher = Firebase.app.get(UserAgentPublisher::class.java) - assertThat(publisher.userAgent).contains(LIBRARY_NAME) - } -} - -@RunWith(RobolectricTestRunner::class) -class AppCheckLimitedUseTest : BaseTestCase() { - @Test - fun `FirebaseFunctions#getHttpsCallable should not use limited-use tokens by default`() { - val callable = Firebase.functions.getHttpsCallable("function") - assertThat(callable.usesLimitedUseFacTokens()).isFalse() - } - - @Test - fun `FirebaseFunctions#getHttpsCallable should build callable with FAC settings (when true)`() { - val callable = - Firebase.functions.getHttpsCallable("function") { limitedUseAppCheckTokens = true } - assertThat(callable.usesLimitedUseFacTokens()).isTrue() - } - - @Test - fun `FirebaseFunctions#getHttpsCallable should build callable with FAC settings (when false)`() { - val callable = - Firebase.functions.getHttpsCallable("function") { limitedUseAppCheckTokens = false } - assertThat(callable.usesLimitedUseFacTokens()).isFalse() - } - - @Test - fun `FirebaseFunctions#getHttpsCallableFromUrl should not use limited-use tokens by default`() { - val callable = Firebase.functions.getHttpsCallableFromUrl(URL("https://functions.test")) - assertThat(callable.usesLimitedUseFacTokens()).isFalse() - } - - @Test - fun `FirebaseFunctions#getHttpsCallableFromUrl callable with FAC settings (when true)`() { - val callable = - Firebase.functions.getHttpsCallableFromUrl(URL("https://functions.test")) { - limitedUseAppCheckTokens = true - } - assertThat(callable.usesLimitedUseFacTokens()).isTrue() - } - - @Test - fun `FirebaseFunctions#getHttpsCallableFromUrl callable with FAC settings (when false)`() { - val callable = - Firebase.functions.getHttpsCallableFromUrl(URL("https://functions.test")) { - limitedUseAppCheckTokens = false - } - assertThat(callable.usesLimitedUseFacTokens()).isFalse() - } -} From 902c8e3151675d93dda49242d4a53f3d77dc0846 Mon Sep 17 00:00:00 2001 From: Emily Ploszaj Date: Fri, 27 Dec 2024 14:22:03 -0600 Subject: [PATCH 5/5] Adjust method visibility on internal class --- .../src/main/java/com/google/firebase/functions/Serializer.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt b/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt index 325d1bb06b2..3ab2ebb0756 100644 --- a/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt +++ b/firebase-functions/src/main/java/com/google/firebase/functions/Serializer.kt @@ -32,7 +32,7 @@ internal class Serializer { dateFormat.timeZone = TimeZone.getTimeZone("UTC") } - internal fun encode(obj: Any?): Any { + public fun encode(obj: Any?): Any { if (obj == null || obj === JSONObject.NULL) { return JSONObject.NULL } @@ -110,7 +110,7 @@ internal class Serializer { throw IllegalArgumentException("Object cannot be encoded in JSON: $obj") } - internal fun decode(obj: Any?): Any? { + public fun decode(obj: Any?): Any? { // TODO: Maybe this should throw a FirebaseFunctionsException instead? if (obj == null) return null if (obj is Number) {