Skip to content
Closed
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
Expand Up @@ -21,7 +21,6 @@ import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import kotlin.test.Ignore

class PingOneProtectInitializeCallbackE2ETest : BaseJourneyTest() {

Expand All @@ -44,10 +43,8 @@ class PingOneProtectInitializeCallbackE2ETest : BaseJourneyTest() {
val pingOneProtectInitializeCallback = node.callbacks.first() as PingOneProtectInitializeCallback

assertTrue(pingOneProtectInitializeCallback.envId != "")
assertFalse(pingOneProtectInitializeCallback.consoleLogEnabled)
assertTrue(pingOneProtectInitializeCallback.deviceAttributesToIgnore.isEmpty())
assertFalse(pingOneProtectInitializeCallback.agentIdentification)
assertTrue(pingOneProtectInitializeCallback.customHost == "")
assertFalse(pingOneProtectInitializeCallback.lazyMetadata)
assertTrue(pingOneProtectInitializeCallback.behavioralDataCollection)

val initResult = pingOneProtectInitializeCallback.start()
Expand All @@ -66,8 +63,6 @@ class PingOneProtectInitializeCallbackE2ETest : BaseJourneyTest() {
assertNotNull(defaultJourney.session())
}

// TODO - This will be fixed when we fix SDKS-4548
@Ignore("Flaky Test - Remove when SDKS-4548 is fixed")
@Test
fun testProtectInitializeCustom() = runTest {
var node = defaultJourney.start(tree) as ContinueNode
Expand All @@ -81,12 +76,8 @@ class PingOneProtectInitializeCallbackE2ETest : BaseJourneyTest() {
val pingOneProtectInitializeCallback = node.callbacks.first() as PingOneProtectInitializeCallback

assertTrue(pingOneProtectInitializeCallback.envId != "")
assertTrue(pingOneProtectInitializeCallback.consoleLogEnabled)
assertTrue(pingOneProtectInitializeCallback.deviceAttributesToIgnore.contains("Model"))
assertTrue(pingOneProtectInitializeCallback.deviceAttributesToIgnore.contains("Manufacturer"))
assertTrue(pingOneProtectInitializeCallback.deviceAttributesToIgnore.contains("Screen size"))
assertTrue(pingOneProtectInitializeCallback.customHost == "custom.host.com")
assertTrue(pingOneProtectInitializeCallback.lazyMetadata)
assertTrue(pingOneProtectInitializeCallback.customHost.isEmpty())
assertTrue(pingOneProtectInitializeCallback.agentIdentification)
assertFalse(pingOneProtectInitializeCallback.behavioralDataCollection)

val initResult = pingOneProtectInitializeCallback.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,12 @@ class MetadataCallbackTest {
"_type": "PingOneProtect",
"_action": "protect_initialize",
"envId" : "02fb4743-189a-4bc7-9d6c-a919edfe6447",
"consoleLogEnabled" : true,
"deviceAttributesToIgnore" : [],
"agentIdentification" : true,
"customHost" : "",
"lazyMetadata" : true,
"behavioralDataCollection" : true,
"disableHub" : true,
"deviceKeyRsyncIntervals" : 10,
"enableTrust" : true,
"universalDeviceIdentification" : true,
"disableTags" : true
}
}
Expand All @@ -229,12 +227,11 @@ class MetadataCallbackTest {
callback.journey = journey
val actualCallback = callback.init(jsonObject)
assertTrue(actualCallback is PingOneProtectInitializeCallback)
assertTrue("02fb4743-189a-4bc7-9d6c-a919edfe6447" == actualCallback.envId)
assertTrue(actualCallback.consoleLogEnabled)
assertTrue(actualCallback.lazyMetadata)
assertEquals("02fb4743-189a-4bc7-9d6c-a919edfe6447", actualCallback.envId)
assertTrue(actualCallback.agentIdentification)
assertTrue(actualCallback.behavioralDataCollection)
assertEquals("", actualCallback.customHost)
assertTrue(actualCallback.deviceAttributesToIgnore.isEmpty())
assertTrue(actualCallback.universalDeviceIdentification)
}

@Test
Expand Down
5 changes: 4 additions & 1 deletion protect/src/main/kotlin/com/pingidentity/protect/Protect.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package com.pingidentity.protect

import com.pingidentity.android.ContextProvider
import com.pingidentity.orchestrate.Module
import com.pingidentity.signalssdk.sdk.GetDataCallback
import com.pingidentity.signalssdk.sdk.InitCallback
import com.pingidentity.signalssdk.sdk.POInitParams
Expand Down Expand Up @@ -149,6 +148,10 @@ open class ProtectConfig {
*/
var isBehavioralDataCollection: Boolean = true

var agentIdentification: Boolean = false
var agentTimeout: Int = 0
var agentPort: Int = 0
var universalDeviceIdentification: Boolean = false
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
package com.pingidentity.protect.journey

import com.pingidentity.protect.Protect
import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.ensureActive
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.boolean
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonPrimitive
import java.util.Collections
import kotlin.coroutines.coroutineContext

/**
* A callback class for initializing the PingOne Protect SDK.
Expand All @@ -25,57 +22,32 @@ import kotlin.coroutines.coroutineContext
*
* @property envId The environment ID for the Protect SDK.
* @property behavioralDataCollection Indicates whether behavioral data collection is enabled.
* @property consoleLogEnabled Indicates whether console logging is enabled.
* @property lazyMetadata Indicates whether lazy metadata loading is enabled.
* @property customHost The custom host for the Protect SDK.
* @property deviceAttributesToIgnore A list of device attributes to ignore.
*/
class PingOneProtectInitializeCallback : AbstractProtectCallback() {

var envId: String = ""
private set
var behavioralDataCollection: Boolean = false
private set

var consoleLogEnabled: Boolean = false
private set

var lazyMetadata: Boolean = false
private set

var customHost: String = ""
private set
var deviceAttributesToIgnore: List<String> = emptyList()
var agentIdentification: Boolean = false
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, it is not clear to me if we should include these new 3 "agent" fields - according the a comment in the ticket:

Agent configuration is only applicable to web SDK

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep the fields then? If they're not being used in our SDK?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vibhorgoswami, it looks like there are many moving parts on the server side. From what I see the callback changes are not finalized... we better hold on with these changes until we get clarity on the requirements...

private set
var universalDeviceIdentification: Boolean = false
private set


override fun init(name: String, value: JsonElement) {
when (name) {
"envId" -> envId = value.jsonPrimitive.content
"behavioralDataCollection" -> behavioralDataCollection = value.jsonPrimitive.boolean
"consoleLogEnabled" -> consoleLogEnabled = value.jsonPrimitive.boolean
"deviceAttributesToIgnore" -> deviceAttributesToIgnore =
getDeviceAttributes(value.jsonArray)

"customHost" -> customHost = value.jsonPrimitive.content
"lazyMetadata" -> lazyMetadata = value.jsonPrimitive.boolean
"agentIdentification" -> agentIdentification = value.jsonPrimitive.boolean
"universalDeviceIdentification" -> universalDeviceIdentification = value.jsonPrimitive.boolean
else -> {}
}
}

/**
* Get the getDeviceAttributes attribute
*
* @param array The data source
*/
private fun getDeviceAttributes(array: JsonArray): List<String> {
val list = mutableListOf<String>()
array.forEach {
list.add(it.jsonPrimitive.content)
}
return Collections.unmodifiableList(list)
}

/**
* Start the PingOne Protect SDK.
* @return A Result containing either success or failure.
Expand All @@ -85,11 +57,9 @@ class PingOneProtectInitializeCallback : AbstractProtectCallback() {
Protect.config {
envId = this@PingOneProtectInitializeCallback.envId.nullIfEmpty()
isBehavioralDataCollection = behavioralDataCollection
isLazyMetadata = lazyMetadata
isConsoleLogEnabled = consoleLogEnabled
deviceAttributesToIgnore =
this@PingOneProtectInitializeCallback.deviceAttributesToIgnore
agentIdentification = this@PingOneProtectInitializeCallback.agentIdentification
customHost = this@PingOneProtectInitializeCallback.customHost.nullIfEmpty()
universalDeviceIdentification = this@PingOneProtectInitializeCallback.universalDeviceIdentification
}
if (behavioralDataCollection) {
Protect.resumeBehavioralData()
Expand All @@ -99,7 +69,7 @@ class PingOneProtectInitializeCallback : AbstractProtectCallback() {
Protect.initialize()
return Result.success(Unit)
} catch (e: Exception) {
coroutineContext.ensureActive()
currentCoroutineContext().ensureActive()
error(e.message ?: CLIENT_ERROR)
return Result.failure(e)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,40 +55,24 @@ class PingOneProtectInitializeCallbackTest {
"value": "02fb4743-189a-4bc7-9d6c-a919edfe6447"
},
{
"name": "consoleLogEnabled",
"name": "agentIdentification",
"value": true
},
{
"name": "deviceAttributesToIgnore",
"value": ["attr1", "attr2"]
},
{
"name": "customHost",
"value": "host.example.com"
},
{
"name": "lazyMetadata",
"value": true
},
{
"name": "behavioralDataCollection",
"value": true
},
{
"name": "deviceKeyRsyncIntervals",
"value": 14
},
{
"name": "enableTrust",
"name": "universalDeviceIdentification",
"value": false
},
{
"name": "disableTags",
"value": false
},
{
"name": "disableHub",
"value": false
}
],
"input": [
Expand All @@ -114,16 +98,16 @@ class PingOneProtectInitializeCallbackTest {

assertEquals("02fb4743-189a-4bc7-9d6c-a919edfe6447", callback.envId)
assertTrue(callback.behavioralDataCollection)
assertTrue(callback.consoleLogEnabled)
assertTrue(callback.lazyMetadata)
assertTrue(callback.agentIdentification)
assertEquals("host.example.com", callback.customHost)
assertEquals(listOf("attr1", "attr2"), callback.deviceAttributesToIgnore)
assertFalse(callback.universalDeviceIdentification)

assertTrue(callback.start().isSuccess)
verify(exactly = 1) { Protect.resumeBehavioralData() }
val payload = callback.payload()
assertTrue(
payload["input"]?.jsonArray?.get(0)?.jsonObject?.get("value")?.jsonPrimitive?.content?.isEmpty() == true
assertEquals(
payload["input"]?.jsonArray?.get(0)?.jsonObject?.get("value")?.jsonPrimitive?.content?.isEmpty(),
true
)
}

Expand Down Expand Up @@ -173,10 +157,8 @@ class PingOneProtectInitializeCallbackTest {

assertEquals("02fb4743-189a-4bc7-9d6c-a919edfe6447", callback.envId)
assertFalse(callback.behavioralDataCollection)
assertFalse(callback.consoleLogEnabled)
assertFalse(callback.lazyMetadata)
assertFalse(callback.agentIdentification)
assertEquals("", callback.customHost)
assertTrue(callback.deviceAttributesToIgnore.isEmpty())
}

@Test
Expand All @@ -192,14 +174,10 @@ class PingOneProtectInitializeCallbackTest {
"_type": "PingOneProtect",
"_action": "protect_initialize",
"envId" : "02fb4743-189a-4bc7-9d6c-a919edfe6447",
"consoleLogEnabled" : true,
"deviceAttributesToIgnore" : [],
"customHost" : "",
"lazyMetadata" : true,
"behavioralDataCollection" : true,
"disableHub" : true,
"deviceKeyRsyncIntervals" : 10,
"enableTrust" : true,
"agentIdentification" : true,
"universalDeviceIdentification" : true,
"disableTags" : true
}
}
Expand All @@ -211,12 +189,11 @@ class PingOneProtectInitializeCallbackTest {
val callback = PingOneProtectInitializeCallback()
val actualCallback = callback.init(jsonObject)
assertTrue(actualCallback is PingOneProtectInitializeCallback)
assertTrue("02fb4743-189a-4bc7-9d6c-a919edfe6447" == actualCallback.envId)
assertTrue(actualCallback.consoleLogEnabled)
assertTrue(actualCallback.lazyMetadata)
assertEquals("02fb4743-189a-4bc7-9d6c-a919edfe6447", actualCallback.envId)
assertTrue(actualCallback.agentIdentification)
assertTrue(actualCallback.behavioralDataCollection)
assertEquals("", actualCallback.customHost)
assertTrue(actualCallback.deviceAttributesToIgnore.isEmpty())
assertTrue(actualCallback.universalDeviceIdentification)

val continueNode = mockk<ContinueNode>()
val hiddenValueCallback = object : ValueCallback {
Expand Down Expand Up @@ -249,14 +226,10 @@ class PingOneProtectInitializeCallbackTest {
"_type": "PingOneProtect",
"_action": "protect_initialize",
"envId" : "02fb4743-189a-4bc7-9d6c-a919edfe6447",
"consoleLogEnabled" : true,
"deviceAttributesToIgnore" : [],
"customHost" : "",
"lazyMetadata" : true,
"behavioralDataCollection" : true,
"disableHub" : true,
"deviceKeyRsyncIntervals" : 10,
"enableTrust" : true,
"agentIdentification" : true,
"universalDeviceIdentification" : true,
"disableTags" : true
}
}
Expand Down
Loading