-
Notifications
You must be signed in to change notification settings - Fork 46
Expose a JavaScript API in brokered Webviews to facilitate Improved Same Device NumberMatch , Fixes AB#3203956 #2617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c4d3c81
1ffa139
243ccd7
ccfe0d2
2945a5f
2bd13c0
f478f41
caf538c
5d26097
ee7a7c7
8ae18e1
bb18c6d
b8ee1ea
0415ee7
ab0a914
9fe183c
0f43c26
b254993
c54ac38
56ff04d
0e092e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // All rights reserved. | ||
| // | ||
| // This code is licensed under the MIT License. | ||
| // | ||
| // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| // of this software and associated documentation files(the "Software"), to deal | ||
| // in the Software without restriction, including without limitation the rights | ||
| // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | ||
| // copies of the Software, and to permit persons to whom the Software is | ||
| // furnished to do so, subject to the following conditions : | ||
| // | ||
| // The above copyright notice and this permission notice shall be included in | ||
| // all copies or substantial portions of the Software. | ||
| // | ||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| // THE SOFTWARE. | ||
| package com.microsoft.identity.common.internal.broker | ||
|
|
||
| import com.google.gson.annotations.SerializedName | ||
|
|
||
| /** | ||
| * Data class representing the JSON payload object received from AuthUX. | ||
| * | ||
| * @property correlationId The correlation ID for the request. | ||
| * @property actionName The name of the action being performed. | ||
| * @property actionComponent The component responsible for the action. | ||
| * @property params The parameters for the action, including function and data. | ||
| */ | ||
| data class AuthUxJsonPayloadObject( | ||
| @SerializedName(SerializedNames.CORRELATIONID) | ||
| val correlationId: String?, | ||
|
|
||
| @SerializedName(SerializedNames.ACTION_NAME) | ||
| val actionName: String?, | ||
|
|
||
| @SerializedName(SerializedNames.ACTION_COMPONENT) | ||
| val actionComponent: String?, | ||
|
|
||
| @SerializedName(SerializedNames.PARAMS) | ||
| val params: AuthUxParams? | ||
shahzaibj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| /** | ||
| * Data class representing the parameters for the action, including function and data. | ||
| * | ||
| * @property function The function to be executed. | ||
| * @property data The data associated with the function. | ||
| */ | ||
| data class AuthUxParams( | ||
| @SerializedName(SerializedNames.FUNCTION) | ||
| val function: String?, | ||
|
|
||
| @SerializedName(SerializedNames.DATA) | ||
| val data: AuthUxData? | ||
| ) | ||
|
|
||
| /** | ||
| * Data class representing the data associated with the JS API call. | ||
| * | ||
| * @property sessionId The session ID for the request. | ||
| * @property numberMatch The number match value. | ||
| */ | ||
| data class AuthUxData( | ||
| @SerializedName(SerializedNames.SESSIONID) | ||
| val sessionId: String?, | ||
|
|
||
| @SerializedName(SerializedNames.NUMBERMATCH) | ||
| val numberMatch: String? | ||
| ) | ||
|
|
||
| object SerializedNames { | ||
| const val CORRELATIONID = "correlationID" | ||
| const val ACTION_NAME = "action_name" | ||
| const val ACTION_COMPONENT = "action_component" | ||
| const val PARAMS = "params" | ||
| const val FUNCTION = "function" | ||
| const val DATA = "data" | ||
| const val SESSIONID = "sessionID" | ||
fadidurah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const val NUMBERMATCH = "numberMatch" | ||
| } | ||
fadidurah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| package com.microsoft.identity.common.internal.broker | ||
|
|
||
| import com.microsoft.identity.common.internal.numberMatch.NumberMatchHelper | ||
| import org.junit.After | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
|
|
||
|
|
@@ -55,6 +56,12 @@ class AuthUxJavaScriptInterfaceTest { | |
| authUxJavaScriptInterface = AuthUxJavaScriptInterface() | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| // Clear the static map after each test | ||
| NumberMatchHelper.numberMatchMap.clear() | ||
| } | ||
|
|
||
| @Test | ||
| fun `test postMessageToBroker with NUMBER_MATCH function`() { | ||
| // Call the method | ||
|
|
@@ -64,4 +71,20 @@ class AuthUxJavaScriptInterfaceTest { | |
| val storedValue = NumberMatchHelper.numberMatchMap[mockSessionId] | ||
| assert(storedValue == mockNumberMatchValue) | ||
| } | ||
|
|
||
| @Test | ||
| fun `test postMessageToBroker with empty json`() { | ||
| // Call the method | ||
| authUxJavaScriptInterface.postMessageToBroker("{}") | ||
|
|
||
| // Should not get an exception | ||
| } | ||
|
|
||
| @Test | ||
| fun `test postMessageToBroker with non-json string`() { | ||
| // Call the method | ||
| authUxJavaScriptInterface.postMessageToBroker("NotAJson") | ||
|
|
||
| // Should not get an exception | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also validate that message was actually posted?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What can be done to validate this? Copilot seems to want to validate the log statement, but can't get it to work |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package com.microsoft.identity.common.internal.broker | ||
fadidurah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import com.google.gson.Gson | ||
| import org.junit.Assert.* | ||
| import org.junit.Test | ||
|
|
||
| class AuthUxJsonPayloadObjectTest { | ||
|
|
||
| private val gson = Gson() | ||
|
|
||
| @Test | ||
| fun `test deserialization of valid JSON`() { | ||
| val json = """ | ||
| { | ||
| "correlationID": "12345", | ||
| "action_name": "write_data", | ||
| "action_component": "broker", | ||
| "params": { | ||
| "function": "NUMBER_MATCH", | ||
| "data": { | ||
| "sessionID": "67890", | ||
| "numberMatch": "123456" | ||
| } | ||
| } | ||
| } | ||
| """.trimIndent() | ||
|
|
||
| val payload = gson.fromJson(json, AuthUxJsonPayloadObject::class.java) | ||
|
|
||
| assertNotNull(payload) | ||
| assertEquals("12345", payload.correlationId) | ||
| assertEquals("write_data", payload.actionName) | ||
| assertEquals("broker", payload.actionComponent) | ||
|
|
||
| val params = payload.params | ||
| assertNotNull(params) | ||
| assertEquals("NUMBER_MATCH", params?.function) | ||
|
|
||
| val data = params?.data | ||
| assertNotNull(data) | ||
| assertEquals("67890", data?.sessionId) | ||
| assertEquals("123456", data?.numberMatch) | ||
| } | ||
|
|
||
| @Test | ||
| fun `test deserialization of JSON with missing fields`() { | ||
| val json = """ | ||
| { | ||
| "correlationID": "12345", | ||
| "action_name": "write_data" | ||
| } | ||
| """.trimIndent() | ||
|
|
||
| val payload = gson.fromJson(json, AuthUxJsonPayloadObject::class.java) | ||
|
|
||
| assertNotNull(payload) | ||
| assertEquals("12345", payload.correlationId) | ||
| assertEquals("write_data", payload.actionName) | ||
| assertNull(payload.actionComponent) | ||
| assertNull(payload.params) | ||
| } | ||
|
|
||
| @Test | ||
| fun `test deserialization of empty JSON`() { | ||
| val json = "{}" | ||
|
|
||
| val payload = gson.fromJson(json, AuthUxJsonPayloadObject::class.java) | ||
|
|
||
| assertNotNull(payload) | ||
| assertNull(payload.correlationId) | ||
| assertNull(payload.actionName) | ||
| assertNull(payload.actionComponent) | ||
| assertNull(payload.params) | ||
| } | ||
| } | ||
fadidurah marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.