Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.onesignal.common

import com.onesignal.debug.internal.logging.Logging
import com.onesignal.internal.SdkOperation

internal fun hasNullByte(value: String?): Boolean = value != null && '\u0000' in value

Expand All @@ -22,6 +23,12 @@ fun isMissing(
return error != null
}

internal fun isMissing(
value: String?,
operation: SdkOperation,
parameter: String,
): Boolean = isMissing(value, "$operation: $parameter")

/**
* Returns true when any of [values] is missing, per [isMissing].
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.onesignal.internal

// Public entry points that wait for or require init. [label] is the API name the app called.
internal enum class SdkOperation(val label: String) {
INIT_WITH_CONTEXT("initWithContext"),
SESSION("Session"),
NOTIFICATIONS("Notifications"),
LOCATION("Location"),
IN_APP_MESSAGES("InAppMessages"),
USER("User"),
LOGIN("login"),
LOGOUT("logout"),
UPDATE_USER_JWT("updateUserJwt"),
JWT_LISTENERS("OneSignal"),
GET_CONSENT_REQUIRED("getConsentRequired"),
SET_CONSENT_REQUIRED("setConsentRequired"),
GET_CONSENT_GIVEN("getConsentGiven"),
SET_CONSENT_GIVEN("setConsentGiven"),
GET_DISABLE_GMS_MISSING_PROMPT("getDisableGMSMissingPrompt"),
SET_DISABLE_GMS_MISSING_PROMPT("setDisableGMSMissingPrompt"),
;

override fun toString() = label
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.onesignal.common

import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import com.onesignal.internal.SdkOperation
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

Expand All @@ -24,4 +25,11 @@ class InputGuardTests : FunSpec({
isMissing("abc\u0000", "addAlias: id") shouldBe true
hasMissingEntries(mapOf("external_id" to "\u0000: 1"), "addAliases", allowEmptyValue = false) shouldBe true
}

test("the operation overload applies the same checks and logs the public API name") {
isMissing(null, SdkOperation.LOGIN, "externalId") shouldBe true
isMissing("\u0000", SdkOperation.LOGIN, "externalId") shouldBe true
isMissing("user-1", SdkOperation.LOGIN, "externalId") shouldBe false
"${SdkOperation.LOGIN}: externalId" shouldBe "login: externalId"
}
})
Loading