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

Wildcard routes aren't supported properly in config #792

Open
aaronpowell opened this issue Jan 2, 2024 · 2 comments · May be fixed by #793
Open

Wildcard routes aren't supported properly in config #792

aaronpowell opened this issue Jan 2, 2024 · 2 comments · May be fixed by #793

Comments

@aaronpowell
Copy link
Contributor

I have a staticwebapp.config.json with a route defined as follows:

{
  "routes": [
    {
      "route": "/manage*",
      "allowedRoles": ["authenticated"]
    }
  ]
}

While this is how you should match a path per the docs, the CLI doesn't correctly generate the regex required to do the wildcard matching, it generates /^\/manage*$/ not /^\/manage.*$/ (not the missing . to indicate the any character after match). There also isn't a test case to cover this in the glob.spec.ts tests.

You can see the failure to find it appropriately looking at the output in the silly logging (it's about a dozen lines down):

[swa] --------------------------------------------------------
[swa] ------------------- processing route -------------------
[swa] --------------------------------------------------------
[swa] processing /manage/events
[swa] checking for matching route
[swa] check if request match route
[swa]  - route: /manage*
[swa]  - wildcard: true
[swa] checking wildcard route
[swa]  - glob: /manage*
[swa]  - pathBeforeWildcard: /manage
[swa] checking if glob expression is valid
[swa]  - glob: /manage*
[swa]  - glob ends with *. Return true
[swa]  - route regexp: /manage*
[swa] turning glob expression into valid RegExp
[swa]  - glob: /manage*
[swa]  - regexp: /^\/manage*$/
[swa]  - isMatch: false
[swa]  - alternateRequestPath: /manage/events/index.html
[swa] checking wildcard route
[swa]  - glob: /manage*
[swa]  - pathBeforeWildcard: /manage
[swa] checking if glob expression is valid
[swa]  - glob: /manage*
[swa]  - glob ends with *. Return true
[swa]  - route regexp: /manage*
[swa] turning glob expression into valid RegExp
[swa]  - glob: /manage*
[swa]  - regexp: /^\/manage*$/
[swa]  - isMatch: false
[swa] checking auth request
[swa]  - not an auth request
[swa] checking function request
[swa]  - not a function request
[swa] checking data-api request
[swa]  - not a data Api request
[swa] checking HTTP method: GET
[swa]  - method is valid (allow-list: GET,HEAD,OPTIONS)
[swa] checking for query params
[swa] checking rewrite auth login request
[swa] checking rewrite auth logout request
[swa] checking authorizations for route
[swa]  - no matching rule
[swa]  - access authorized
[swa] using userConfig
[swa] - userConfig:
[swa]  - routes:
[swa]   - 0:
[swa]     - route: /manage*
[swa]    - allowedRoles:
[swa]      - 0: authenticated
[swa]  - responseOverrides:
[swa]   - 401:
[swa]     - rewrite: /
[swa]     - statusCode: 200
[swa] checking storage content
[swa] remote dev server detected.
[swa]  - url: /manage/events
[swa]  - target: http://localhost:5175
[swa] customUrl: false
[swa] is4xx: false
[swa] remote dev server detected. Proxying request
[swa]  - url: /manage/events
[swa]  - code: 200
[swa] GET http://localhost:5175/manage/events (proxy)
[swa] Connected to tcp:127.0.0.1:5175 successfully
[swa] http://localhost:5175 validated successfully
[swa] Connected to tcp:localhost:5175 successfully
[swa] getting response from dev server
[swa] GET http://localhost:5176/manage/events - 200
aaronpowell added a commit to aaronpowell/swa-emulator that referenced this issue Jan 2, 2024
aaronpowell added a commit to aaronpowell/swa-emulator that referenced this issue Jan 2, 2024
Improved the string replacement to generate the regex (such as leaving the . in for extensions)
Updated tests to understand the new regex structure
@aaronpowell aaronpowell linked a pull request Jan 2, 2024 that will close this issue
@itpropro
Copy link

itpropro commented Mar 4, 2024

Any updates on this @cjk7989 ?
Wildcards not working correctly in local development makes testing more complex route permissions impossible.

@itpropro
Copy link

itpropro commented Apr 8, 2024

@thomasgauvin I just ran into this again in a customer scenario with local integration and e2e tests, any roadmap on this?

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

Successfully merging a pull request may close this issue.

2 participants