Skip to content

Commit

Permalink
Add manual testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jinliu9508 committed May 30, 2024
1 parent 4e8882f commit 52edda4
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
Expand Down Expand Up @@ -83,6 +84,10 @@ public class MainActivityViewModel implements ActivityViewModel, IPushSubscripti
private Button loginUserButton;
private Button logoutUserButton;

// JWT
private Button invalidateJwtButton;
private Button updateJwtButton;

// Alias
private TextView aliasTitleTextView;
private RecyclerView aliasesRecyclerView;
Expand Down Expand Up @@ -211,6 +216,9 @@ public ActivityViewModel onActivityCreated(Context context) {
loginUserButton = getActivity().findViewById(R.id.main_activity_login_user_button);
logoutUserButton = getActivity().findViewById(R.id.main_activity_logout_user_button);

invalidateJwtButton = getActivity().findViewById(R.id.main_activity_invalidate_jwt_button);
updateJwtButton = getActivity().findViewById(R.id.main_activity_update_jwt_button);

aliasTitleTextView = getActivity().findViewById(R.id.main_activity_aliases_title_text_view);
noAliasesTextView = getActivity().findViewById(R.id.main_activity_aliases_no_aliases_text_view);
addAliasButton = getActivity().findViewById(R.id.main_activity_add_alias_button);
Expand Down Expand Up @@ -403,7 +411,7 @@ private void setupAppLayout() {
@Override
public void onSuccess(String update) {
if (update != null && !update.isEmpty()) {
String jwt = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIxNjg4ZDhmMi1kYTdmLTQ4MTUtOGVlMy05ZDEzNzg4NDgyYzgiLCJpYXQiOjE3MTQwODA4MTMsImlkZW50aXR5Ijp7ImV4dGVybmFsX2lkIjoiMjAyNDA0MjUtYWxleDQyIn0sInN1YnNjcmlwdGlvbiI6W3sidHlwZSI6IiIsImlkIjoiMmRlZGU3MzItMTEyNi00MTlkLTk5M2UtNDIzYWQyYTZiZGU5In1dfQ.rzZ-HaDm1EwxbMxd8937bWzPhPSQDDSqSzaASgZZc5A5v8g6ZQHizN9CljOmoQ4lTLm7noD6rOmR07tlZdrI5w";
String jwt = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIxNjg4ZDhmMi1kYTdmLTQ4MTUtOGVlMy05ZDEzNzg4NDgyYzgiLCJpYXQiOjE3MTU5NzMwNzAsImlkZW50aXR5Ijp7ImV4dGVybmFsX2lkIjoiYWxleC0wNTE3Iiwib25lc2lnbmFsX2lkIjoiMGIzYWMyN2EtYWQ4Yi00MWVjLWJhYTYtMzI0NmNkODIyMjJkIn0sInN1YnNjcmlwdGlvbnMiOlt7InR5cGUiOiJFbWFpbCIsInRva2VuIjoiYWxleHRzYXktMDUxN0BvbmVzaWduYWwuY29tIn0seyJ0eXBlIjoiQW5kcm9pZFB1c2giLCJpZCI6ImFkMTAxY2FjLTA5MWItNDkyYy04OGJiLTgxNmZkNTNjYTBmMSJ9XX0._tlD2X8J16gDkP7__FJ8CwpqCLDwb8T14m2ugJwQvuQqbIn4b8o75cKbffbjVGcKP3YaudLCebit53aR9LTQCw";
OneSignal.login(update, jwt);
refreshState();
}
Expand All @@ -423,6 +431,7 @@ public void onFailure() {
}

private void setupUserLayout() {
setupJWTLayout();
setupAliasLayout();
setupEmailLayout();
setupSMSLayout();
Expand All @@ -431,6 +440,30 @@ private void setupUserLayout() {
setupTriggersLayout();
}

private void setupJWTLayout() {
invalidateJwtButton.setOnClickListener(v -> {
OneSignal.updateUserJwt(OneSignal.getUser().getExternalId(), "");
});
updateJwtButton.setOnClickListener(v -> {
dialog.createUpdateAlertDialog("", Dialog.DialogAction.UPDATE, ProfileUtil.FieldType.JWT, new UpdateAlertDialogCallback() {
@Override
public void onSuccess(String update) {
if (update != null && !update.isEmpty()) {
OneSignal.updateUserJwt(OneSignal.getUser().getExternalId(), update);
//String jwt = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIxNjg4ZDhmMi1kYTdmLTQ4MTUtOGVlMy05ZDEzNzg4NDgyYzgiLCJpYXQiOjE3MTQwODA4MTMsImlkZW50aXR5Ijp7ImV4dGVybmFsX2lkIjoiMjAyNDA0MjUtYWxleDQyIn0sInN1YnNjcmlwdGlvbiI6W3sidHlwZSI6IiIsImlkIjoiMmRlZGU3MzItMTEyNi00MTlkLTk5M2UtNDIzYWQyYTZiZGU5In1dfQ.rzZ-HaDm1EwxbMxd8937bWzPhPSQDDSqSzaASgZZc5A5v8g6ZQHizN9CljOmoQ4lTLm7noD6rOmR07tlZdrI5w";
//OneSignal.login(update, jwt);
refreshState();
}
}

@Override
public void onFailure() {

}
});
});
}

private void setupAliasLayout() {
setupAliasesRecyclerView();
addAliasButton.setOnClickListener(v -> dialog.createAddPairAlertDialog("Add Alias", ProfileUtil.FieldType.ALIAS, new AddPairAlertDialogCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum FieldType {
ALIAS("Alias"),
EMAIL("Email"),
SMS("SMS"),
JWT("JWT"),
EXTERNAL_USER_ID("External User Id"),

TAG("Tags"),
Expand Down Expand Up @@ -97,6 +98,10 @@ public static boolean isSMSValid(TextInputLayout smsTextInputLayout) {
return true;
}

private static boolean isJWTValid(TextInputLayout jwtTextInputLayout) {
return !jwtTextInputLayout.getEditText().toString().isEmpty();
}

private static boolean isExternalUserIdValid(TextInputLayout externalUserIdTextInputLayout) {
externalUserIdTextInputLayout.setErrorEnabled(false);
if (externalUserIdTextInputLayout.getEditText() != null) {
Expand Down Expand Up @@ -137,6 +142,8 @@ static boolean isContentValid(FieldType field, TextInputLayout alertDialogTextIn
return isEmailValid(alertDialogTextInputLayout);
case SMS:
return isSMSValid(alertDialogTextInputLayout);
case JWT:
return isJWTValid(alertDialogTextInputLayout);
case EXTERNAL_USER_ID:
return isExternalUserIdValid(alertDialogTextInputLayout);
case TAG:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,20 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:gravity="start|center_vertical"
android:layout_marginBottom="4dp"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_marginBottom="4dp"
android:gravity="start|center_vertical"
android:text="@string/app"
android:textColor="@color/colorDarkText" />

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="12dp"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="12dp"
app:cardCornerRadius="6dp"
app:cardElevation="4dp">

Expand Down Expand Up @@ -226,23 +226,23 @@
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="12dp"
android:orientation="vertical"
android:background="@color/colorPrimary">
android:background="@color/colorPrimary"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/main_activity_app_revoke_consent_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_selector_white_red"
android:text="@string/revoke_consent"
android:textSize="19sp"
android:textColor="@android:color/white"
android:background="@drawable/ripple_selector_white_red"
android:visibility="visible"/>
android:textSize="19sp"
android:visibility="visible" />

</LinearLayout>

Expand All @@ -263,11 +263,11 @@
android:id="@+id/main_activity_login_user_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_selector_white_red"
android:text="@string/login_user"
android:textSize="19sp"
android:textColor="@android:color/white"
android:background="@drawable/ripple_selector_white_red"
android:visibility="visible"/>
android:textSize="19sp"
android:visibility="visible" />

</LinearLayout>

Expand All @@ -288,14 +288,97 @@
android:id="@+id/main_activity_logout_user_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_selector_white_red"
android:text="@string/logout_user"
android:textSize="19sp"
android:textColor="@android:color/white"
android:background="@drawable/ripple_selector_white_red"
android:visibility="visible"/>
android:textSize="19sp"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>

<LinearLayout
android:id="@+id/main_activity_jwt_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical">

<TextView
android:id="@+id/main_activity_jwt_title_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_marginBottom="4dp"
android:gravity="start|center_vertical"
android:text="@string/JWT"
android:textColor="@color/colorDarkText" />

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="12dp"
android:layout_marginBottom="12dp"
app:cardCornerRadius="6dp"
app:cardElevation="4dp">

<LinearLayout
android:id="@+id/main_activity_jwt_details_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="4dp"
android:background="@color/colorPrimary"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/main_activity_invalidate_jwt_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_selector_white_red"
android:text="@string/invalidate_JWT"
android:textColor="@android:color/white"
android:textSize="19sp"
android:visibility="visible" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="4dp"
android:background="@color/colorPrimary"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/main_activity_update_jwt_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ripple_selector_white_red"
android:text="@string/update_JWT"
android:textColor="@android:color/white"
android:textSize="19sp"
android:visibility="visible" />
</LinearLayout>

</LinearLayout>

</androidx.cardview.widget.CardView>

</LinearLayout>

<!-- Aliases -->
<LinearLayout
android:id="@+id/main_activity_aliases_linear_layout"
Expand Down
5 changes: 5 additions & 0 deletions Examples/OneSignalDemo/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<string name="login_user">Login User</string>
<string name="logout_user">Logout User</string>

<string name="JWT">JWT</string>
<string name="invalidate_JWT">Invalidate JWT</string>
<string name="update_JWT">Update JWT</string>
<string name="no_jwt_added">No JWT Added</string>

<string name="aliases">Aliases</string>
<string name="external_user_id_colon">EUID:</string>
<string name="no_aliases_added">No Aliases Added</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class ParamsBackendService(
paramsUrl += "?player_id=$subscriptionId"
}

val response = _http.get(paramsUrl, CacheKeys.REMOTE_PARAMS)
val response = _http.get(paramsUrl, CacheKeys.REMOTE_PARAMS, "")

if (!response.isSuccess) {
throw BackendException(response.statusCode, response.payload, response.retryAfterSeconds)
Expand Down Expand Up @@ -59,8 +59,9 @@ internal class ParamsBackendService(
return ParamsObject(
googleProjectNumber = responseJson.safeString("android_sender_id"),
enterprise = responseJson.safeBool("enterp"),
// TODO: New
useIdentityVerification = responseJson.safeBool("require_ident_auth"),
// TODO: TESTING ONLY
useIdentityVerification = true,
// useIdentityVerification = responseJson.safeBool("require_ident_auth"),
notificationChannels = responseJson.optJSONArray("chnl_lst"),
firebaseAnalytics = responseJson.safeBool("fba"),
restoreTTLFilter = responseJson.safeBool("restore_ttl_filter"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ internal class HttpClient(
con.setRequestProperty("SDK-Version", "onesignal/android/" + OneSignalUtils.SDK_VERSION)

if (!jwt.isNullOrEmpty()) {
con.setRequestProperty("Authentication", "Bearer $jwt")
con.setRequestProperty("Authorization", "Bearer $jwt")
}

if (OneSignalWrapper.sdkType != null && OneSignalWrapper.sdkVersion != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,11 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
token: String,
) {
if (!identityModelStore!!.model.externalId.equals(externalId)) {
Logging.log(LogLevel.DEBUG, "JWT $token is NOT updated for externalId $externalId")
return
}

Logging.log(LogLevel.DEBUG, "JWT $token is updated for externalId $externalId")
identityModelStore!!.model.jwtToken = token
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ package com.onesignal.user.internal.identity
import com.onesignal.common.modeling.SimpleModelStore
import com.onesignal.common.modeling.SingletonModelStore
import com.onesignal.core.internal.preferences.IPreferencesService
import com.onesignal.user.internal.backend.IdentityConstants

open class IdentityModelStore(prefs: IPreferencesService) : SingletonModelStore<IdentityModel>(
SimpleModelStore({ IdentityModel() }, "identity", prefs),
) {
fun invalidateJwt() {
model.setStringProperty(
IdentityConstants.JWT_TOKEN,
"",
)
model.jwtToken = ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ class UpdateSubscriptionOperation() : Operation(SubscriptionOperationExecutor.UP
var jwt: String?
get() = getStringProperty(::jwt.name)
private set(value) {
setStringProperty(::jwt.name, value!!)
if (value != null) {
setStringProperty(::jwt.name, value!!)
}
}

override val createComparisonKey: String get() = "$appId.User.$onesignalId"
Expand Down

0 comments on commit 52edda4

Please sign in to comment.