Skip to content
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

Unable to pass JWT token via extras in startActivity method #848

Open
skibos opened this issue Dec 10, 2024 · 2 comments
Open

Unable to pass JWT token via extras in startActivity method #848

skibos opened this issue Dec 10, 2024 · 2 comments

Comments

@skibos
Copy link

skibos commented Dec 10, 2024

Hi.

Im trying to pass via extras random JWT token to my activity. My code looks in a following way:

    await driver?.execute('mobile: startActivity', {
      intent: 'example_intent',
      extras: [
        [
          's',
          'authToken',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZDE4MTg3OS02NzdjLTQzODQtOTE0NC0xMmY0M2FhOTJiMjkiLCJ1bmlxdWVfbmFtZSI6ImFkMTgxODc5LTY3N2MtNDM4NC05MTQ0LTEyZjQzYWE5MmIyOSIsImp0aSI6IjIxYmU3NzcxLTU1OTAtNDVjOS1hNTgyLTVjOTBjNTM0ZDc0OCIsImlhdCI6IjE3MzM4MzcyMTU4MDkiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJDbGllbnQiLCJuYmYiOjE3MzM4MzcyMTUsImV4cCI6MzMyMzgzMDEyMTUsImlzcyI6ImJlYXV0eWJveCJ9.BuAOPTVC1GXX4zSwH0ItP-yfsxvcFng90bp44lXeuvA',
        ],
        ['s', 'varName2', 'My String2'],
        ['ia', 'arrName', '1,2,3,4'],
      ],
    });

In appium logs I see that under the hood command is not parsed correctly:

[478ae273][AndroidUiautomator2Driver@7a99] Calling AppiumDriver.execute() with args: ["mobile: startActivity",[{"intent":"example_intent","extras":[["s","authToken","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZDE4MTg3OS02NzdjLTQzODQtOTE0NC0xMmY0M2FhOTJiMjkiLCJ1bmlxdWVfbmFtZSI6ImFkMTgxODc5LTY3N2MtNDM4NC05MTQ0LTEyZjQzYWE5MmIyOSIsImp0aSI6IjIxYmU3NzcxLTU1OTAtNDVjOS1hNTgyLTVjOTBjNTM0ZDc0OCIsImlhdCI6IjE3MzM4MzcyMTU4MDkiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJDbGllbnQiLCJuYmYiOjE3MzM4MzcyMTUsImV4cCI6MzMyMzgzMDEyMTUsImlzcyI6ImJlYXV0eWJveCJ9.BuAOPTVC1GXX4zSwH0ItP-yfsxvcFng90bp44lXeuvA"],["s","varName2","My String2"],["ia","arrName","1,2,3,4"]]}],"478ae273-7d92-4544-8227-cdcd9407ca40"]
[478ae273][ADB] Running '/Users/x/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am start-activity example_intent --es authToken eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZDE4MTg3OS02NzdjLTQzODQtOTE0NC0xMmY0M2FhOTJiMjkiLCJ1bmlxdWVfbmFtZSI6ImFkMTgxODc5LTY3N2MtNDM4NC05MTQ0LTEyZjQzYWE5MmIyOSIsImp0aSI6IjIxYmU3NzcxLTU1OTAtNDVjOS1hNTgyLTVjOTBjNTM0ZDc0OCIsImlhdCI6IjE3MzM4MzcyMTU4MDkiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJDbGllbnQiLCJuYmYiOjE3MzM4MzcyMTUsImV4cCI6MzMyMzgzMDEyMTUsImlzcyI6ImJlYXV0eWJveCJ9.BuAOPTVC1GXX4zSwH0ItP-yfsxvcFng90bp44lXeuvA --es varName2 'My String2' --eia arrName 1\,2\,3\,4'
[478ae273][AndroidUiautomator2Driver@7a99] Responding to client with driver.execute() result: "Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=example_intent }"

It looks like there are missing ' ' in the start and end of JWT passed to ADB. In documentation there is said also that string must be valid - what does it mean?

The purpose of passing JWT via extras is to have possibility to skip whole login/register flow and speed up my tests.

@mykola-mokhnach
Copy link
Contributor

not sure what is the problem here. The token string is base64-encoded. It does not have any chars that require escaping

@skibos
Copy link
Author

skibos commented Dec 11, 2024

I use package https://www.npmjs.com/package/react-native-launch-arguments

The thing is that:

adb -P 5037 -s emulator-5554 shell am start-activity my_package/my_activity --es authToken eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZDE4MTg3OS02NzdjLTQzODQtOTE0NC0xMmY0M2FhOTJiMjkiLCJ1bmlxdWVfbmFtZSI6ImFkMTgxODc5LTY3N2MtNDM4NC05MTQ0LTEyZjQzYWE5MmIyOSIsImp0aSI6IjIxYmU3NzcxLTU1OTAtNDVjOS1hNTgyLTVjOTBjNTM0ZDc0OCIsImlhdCI6IjE3MzM4MzcyMTU4MDkiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJDbGllbnQiLCJuYmYiOjE3MzM4MzcyMTUsImV4cCI6MzMyMzgzMDEyMTUsImlzcyI6ImJlYXV0eWJveCJ9.BuAOPTVC1GXX4zSwH0ItP-yfsxvcFng90bp44lXeuvA

which plugin is executing doesn't work. I did small investigation and "" doesnt matter.

When I run this command in CMD - get response which looks like:

"Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=my_package/my_activity }"

It seems extras aren't passed to the activity. (?)

I tried different approach and I added -n before my_package/my_activity and

adb -P 5037 -s emulator-5554 shell am start-activity -n my_package/my_activity --es authToken eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZDE4MTg3OS02NzdjLTQzODQtOTE0NC0xMmY0M2FhOTJiMjkiLCJ1bmlxdWVfbmFtZSI6ImFkMTgxODc5LTY3N2MtNDM4NC05MTQ0LTEyZjQzYWE5MmIyOSIsImp0aSI6IjIxYmU3NzcxLTU1OTAtNDVjOS1hNTgyLTVjOTBjNTM0ZDc0OCIsImlhdCI6IjE3MzM4MzcyMTU4MDkiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJDbGllbnQiLCJuYmYiOjE3MzM4MzcyMTUsImV4cCI6MzMyMzgzMDEyMTUsImlzcyI6ImJlYXV0eWJveCJ9.BuAOPTVC1GXX4zSwH0ItP-yfsxvcFng90bp44lXeuvA

and response from emulator was:

Starting: Intent { cmp=my_package/my_activity (has extras) }

also package from react native manage to fetch my extras. I tried to pass also via driver.execute additional parameter "component" which was the same like intent:

await driver?.execute('mobile: startActivity', {
  intent: 'my_package/my_activity',
  component: 'my_package/my_activity',
  extras: [
    [
      's',
      'authToken',

'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZDE4MTg3OS02NzdjLTQzODQtOTE0NC0xMmY0M2FhOTJiMjkiLCJ1bmlxdWVfbmFtZSI6ImFkMTgxODc5LTY3N2MtNDM4NC05MTQ0LTEyZjQzYWE5MmIyOSIsImp0aSI6IjIxYmU3NzcxLTU1OTAtNDVjOS1hNTgyLTVjOTBjNTM0ZDc0OCIsImlhdCI6IjE3MzM4MzcyMTU4MDkiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJDbGllbnQiLCJuYmYiOjE3MzM4MzcyMTUsImV4cCI6MzMyMzgzMDEyMTUsImlzcyI6ImJlYXV0eWJveCJ9.BuAOPTVC1GXX4zSwH0ItP-yfsxvcFng90bp44lXeuvA',
],
],
});

adb -P 5037 -s emulator-5554 shell am start-activity my_package/my_activity -n my_package/my_activity --es authToken eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJhZDE4MTg3OS02NzdjLTQzODQtOTE0NC0xMmY0M2FhOTJiMjkiLCJ1bmlxdWVfbmFtZSI6ImFkMTgxODc5LTY3N2MtNDM4NC05MTQ0LTEyZjQzYWE5MmIyOSIsImp0aSI6IjIxYmU3NzcxLTU1OTAtNDVjOS1hNTgyLTVjOTBjNTM0ZDc0OCIsImlhdCI6IjE3MzM4MzcyMTU4MDkiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJDbGllbnQiLCJuYmYiOjE3MzM4MzcyMTUsImV4cCI6MzMyMzgzMDEyMTUsImlzcyI6ImJlYXV0eWJveCJ9.BuAOPTVC1GXX4zSwH0ItP-yfsxvcFng90bp44lXeuvA

but still response was:

"Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=my_package/my_activity }"

The easiest way to resolve it I think would be mark intent as optional but maybe problem is somewhere else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants