Skip to content

Incorrect localStorage value after running authentication setup test. #160

@dtng95

Description

@dtng95
  • I got this issue SyntaxError: Unexpected number in JSON at position 4 when running my tests for Forms.
image
  • After some digging, I found out that the user.json file that has been generated by the authentication setup test has an issue. Here's my user.json file looks like.
{
  "cookies": [
    {
      "name": "UMB_UCONTEXT",
      "value": "too long so I replace with this text",
      "domain": "localhost",
      "path": "/",
      "expires": 1730285391.9487,
      "httpOnly": true,
      "secure": true,
      "sameSite": "Lax"
    }
  ],
  "origins": [
    {
      "origin": "https://localhost:44337",
      "localStorage": [
        {
          "name": "umb:serverUpgradeCheck",
          "value": "{\"type\":\"Minor\",\"comment\":\"14.3.1.0 is released. Upgrade today - it's free!\",\"url\":\"http://our.umbraco.org/contribute/releases/1431?version=14.3.0\",\"expires\":\"2024-11-06T10:29:53.981Z\"}"
        },
        {
          "name": "umb:lastUpgradeCheck",
          "value": "2024-10-30T10:29:53.517Z"
        },
        {
          "name": "umb:userAuthTokenResponse",
          "value": "{\"access_token\":\"MbUYnSVIAxyFPERMF2K-4eKEGhmStVoHVlpmoHfy8X8\",\"refresh_token\":\"-9oFAFT4vmhCvwmZkhF4OEhw4TRqsUELbz_5yjpwr34\",\"scope\":\"offline_access\",\"token_type\":\"Bearer\",\"issued_at\":1730284192,\"expires_in\":\"300\"}"
        }
      ]
    }
  ]
}
  • By removing umb:lastUpgradeCheck, my tests run successfully. I figured out the value 2024-10-30T10:29:53.517Z is somehow causing the issue. I updated it to this:
{
  "name": "umb:lastUpgradeCheck",
  "value": "{\"date\":\"2024-10-30T09:24:53.264Z\"}
}

and everything is ok.

  • Also, by looking at the updateLocalStorage() in ApiHelpers, I believe using data.origins[0].localStorage[0] to get umb:userAuthTokenResponse is inappropriate. With my above json file, umb:userAuthTokenResponse is the third element, not the first, so data.origins[0].localStorage[0] would return incorrect result.
    I would suggest using other approach like
    data.origins[0].localStorage.find(l => l.name == "umb:userAuthTokenResponse") or any other approach that fits would be better.

  • I'm not really sure if this is the correct repo to create this issue or not. Let me know if I need to create this in another repo.
    Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions