forked from OpenStackweb/call-for-presentations
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: validate the landing selection plan id before building URLs from it #91
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6bcfd4b
fix: validate landing selection plan before redirecting to profile
smarcet 1f24aef
fix: build nav menu links from the validated landing selection plan
smarcet b3f15e5
chore: add jest so the unit tests are runnable outside a dev machine
smarcet 6269623
fix: validate the landing selection plan in getSubmissionsPath
smarcet 764a213
ci: run the jest suite on push and pull request
smarcet a14e934
chore: drop unused getSubmissionsPath import from ProfilePage
smarcet c9cf65d
chore: remove dead getLandingSelectionPlanId export
smarcet 2e5d1d0
docs: fix getAllowedLandingSelectionPlanId's contract wording
smarcet d31790e
test: restore global.localStorage after each spec in methods.test.js
smarcet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| name: jest | ||
|
|
||
| on: [push, pull_request] | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 | ||
|
smarcet marked this conversation as resolved.
|
||
| - uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: 22 | ||
|
smarcet marked this conversation as resolved.
|
||
| - run: yarn install | ||
|
smarcet marked this conversation as resolved.
|
||
| - run: yarn test | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Babel config used by jest (babel-jest). It is scoped to the "test" env so the | ||
| // webpack build is left untouched: webpack.common.js configures babel-loader | ||
| // with inline presets, and for non-test envs this file contributes nothing. | ||
| module.exports = { | ||
| env: { | ||
| test: { | ||
| presets: [ | ||
| ['@babel/preset-env', { targets: { node: 'current' } }], | ||
| '@babel/preset-react', | ||
| '@babel/preset-flow' | ||
| ] | ||
| } | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| module.exports = { | ||
| testEnvironment: 'node', | ||
| testMatch: ['**/src/**/*.test.js'] | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /** | ||
| * Copyright 2018 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| **/ | ||
|
|
||
| import { getAllowedLandingSelectionPlanId, getSubmissionsPath } from './methods'; | ||
| import { SP_LANDING } from './constants'; | ||
|
|
||
| const originalLocalStorage = global.localStorage; | ||
|
|
||
| afterEach(() => { | ||
| global.localStorage = originalLocalStorage; | ||
| }); | ||
|
|
||
| const setLanding = (value) => { | ||
| global.localStorage = { | ||
|
smarcet marked this conversation as resolved.
|
||
| getItem: (key) => (key === SP_LANDING && value !== null ? String(value) : null) | ||
| }; | ||
| }; | ||
|
|
||
| const summitWithPlans = (...ids) => ({selection_plans: ids.map(id => ({id}))}); | ||
|
|
||
| describe('getAllowedLandingSelectionPlanId', () => { | ||
| it('returns the landing plan id when the user is allowed to submit to it', () => { | ||
| setLanding(123); | ||
|
|
||
| expect(getAllowedLandingSelectionPlanId(summitWithPlans(45, 123))).toBe(123); | ||
| }); | ||
|
|
||
| it('returns null when the landing plan is not among the allowed plans', () => { | ||
| // stale SP_LANDING: id kept from another summit or a closed plan. | ||
| // this is the precondition of the /all-plans/{id}/profile redirect loop | ||
| setLanding(999); | ||
|
|
||
| expect(getAllowedLandingSelectionPlanId(summitWithPlans(45, 123))).toBeNull(); | ||
| }); | ||
|
|
||
| it('returns null when no landing plan was ever stored', () => { | ||
| setLanding(null); | ||
|
|
||
| expect(getAllowedLandingSelectionPlanId(summitWithPlans(45, 123))).toBeNull(); | ||
| }); | ||
|
|
||
| it('returns null when the stored value is not a usable plan id', () => { | ||
| setLanding(''); | ||
| expect(getAllowedLandingSelectionPlanId(summitWithPlans(45, 123))).toBeNull(); | ||
|
|
||
| setLanding('not-a-plan'); | ||
| expect(getAllowedLandingSelectionPlanId(summitWithPlans(45, 123))).toBeNull(); | ||
| }); | ||
|
|
||
| it('returns null for a non-positive id even if a plan matches it', () => { | ||
| setLanding(0); | ||
|
|
||
| expect(getAllowedLandingSelectionPlanId(summitWithPlans(0, 123))).toBeNull(); | ||
| }); | ||
|
|
||
| it('returns null when the allowed plans are not loaded yet', () => { | ||
| setLanding(123); | ||
|
|
||
| expect(getAllowedLandingSelectionPlanId(undefined)).toBeNull(); | ||
| expect(getAllowedLandingSelectionPlanId({})).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getSubmissionsPath', () => { | ||
| it('keeps the landing plan in the path when the user can submit to it', () => { | ||
| setLanding(123); | ||
|
|
||
| expect(getSubmissionsPath(summitWithPlans(45, 123))).toBe('all-plans/123'); | ||
| }); | ||
|
|
||
| it('falls back to the global submissions path when the landing plan is stale', () => { | ||
| setLanding(999); | ||
|
|
||
| expect(getSubmissionsPath(summitWithPlans(45, 123))).toBe('all-plans'); | ||
| }); | ||
|
|
||
| it('falls back to the global submissions path when no landing plan was stored', () => { | ||
| setLanding(null); | ||
|
|
||
| expect(getSubmissionsPath(summitWithPlans(45, 123))).toBe('all-plans'); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.