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

Add centralized request service #4758

Merged
merged 23 commits into from
Nov 7, 2022

Conversation

Tostti
Copy link
Member

@Tostti Tostti commented Oct 24, 2022

Description

This PR creates a centralized request service for the plugin

Issues Resolved

#4757

Service description

The created service has an async function named request, that can be called from different places in the code. It also contains a function named initializeInterceptor, which must be called at the plugin's start in order to define the interceptor.

The request function receives an object with the next parameters:

Method: GET, PUT, POST, DELETE, PATCH
Headers: an object with the desired headers. Plugin platform and content type headers are not needed.
Path: the path to which the request should be made. It can include queries, and should not include the basePath.
Data: the payload of the request.
Timeout: desired timeout in ms. If it's missing or the value is 0, no timeout will be set.
Once executed, it returns a promise. If there are no errors, it will be accepted and contain the result of the request. If there are errors, it will be rejected and contain the error.

This function makes the request with the core.http.fetch service. If there is a 401 unauthorized response from the server, due to the session expired, it will prevent doing any other request, abort the current ones and reload the page to trigger the login process. The prevention and abortion of new requests can also be done externally with the disableRequests function.

This PR also adds a verification on the server definition to prevent the component from making requests if the user is not authenticated. This is because on the reload/login process sometimes the plugin was initialized, a request was done and that caused the login process to be broken. There is detailed information about that on #4757

Check List

  • All tests pass
    • yarn test:jest
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Manual testing

To test the integration of the service, an environment of OSD with SAML is required. It is recommended to add the following line to opensearch_dashboards.yml: opensearch_security.session.ttl: 10000. That will make the session to be invalid after 10 seconds of inactivity (default is 1h)

Scenario: Log in with SAML
Given the idle time after logging in is less than the session validity (10s in the above example)
When the Wazuh app is opened
Then it should open without crashing

Scenario: Log in with SAML
Given the idle time after logging in is more than the session validity (10s in the above example)
When the Wazuh app is opened
Then the system should revalidate the SAML session and redirect to the home page (not Wazuh)

Scenario: Log in with SAML and immediately after that open the Wazuh App
Given the idle time after opening the app is less than the session validity (10s in the above example)
When an interaction happens
Then it should work normally, with the expected behavior of that interaction.

Scenario: Log in with SAML and immediately after that open the Wazuh App
Given the idle time after opening the app is more than the session validity (10s in the above example)
When an interaction happens
Then the system should revalidate the SAML session and redirect to the home page (not Wazuh)

@Tostti Tostti self-assigned this Oct 24, 2022
@Tostti Tostti linked an issue Oct 24, 2022 that may be closed by this pull request
@Tostti Tostti marked this pull request as ready for review November 3, 2022 11:29
@Tostti Tostti requested a review from a team as a code owner November 3, 2022 11:29
@Tostti Tostti changed the title feature/create-centralized-request-service feature/create-centralized-request-service-Wz Nov 3, 2022
@Tostti Tostti changed the title feature/create-centralized-request-service-Wz feature/create-centralized-request-service Nov 3, 2022
@Tostti Tostti marked this pull request as draft November 4, 2022 12:46
@Tostti Tostti removed a link to an issue Nov 7, 2022
1 task
@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2022

Code coverage (Jest) % values
Statements 8.56% ( 3155 / 36835 )
Branches 4.38% ( 1254 / 28580 )
Functions 7.41% ( 677 / 9136 )
Lines 8.63% ( 3044 / 35258 )

@Mayons95 Mayons95 self-requested a review November 7, 2022 16:05
Copy link
Contributor

@Mayons95 Mayons95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TR: ✔️
LGTM
Attached Evidence

Test case 1)

Screencast.from.07-11-22.12.48.35.webm

Test case 2)

Screencast.from.07-11-22.12.49.45.webm

Test case 3)

Screencast.from.07-11-22.12.51.34.webm

Test case 4)

Screencast.from.07-11-22.12.52.40.webm

@Mayons95
Copy link
Contributor

Mayons95 commented Nov 7, 2022

With @Tostti we found an error with the expire session on Open search Logout. The logout service return a 401 error when te session expires.

IMG_1979.MOV

@Tostti Tostti merged commit 34c3fae into 4.4-2.3-wzd Nov 7, 2022
@Tostti Tostti deleted the feature/create-centralized-request-service branch November 7, 2022 19:08
@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2022

The backport to 4.3-7.16 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.3-7.16 4.3-7.16
# Navigate to the new working tree
cd .worktrees/backport-4.3-7.16
# Create a new branch
git switch --create backport-4758-to-4.3-7.16
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 34c3fae84fe27d41330777996ee4b53c6d43e66f
# Push it to GitHub
git push --set-upstream origin backport-4758-to-4.3-7.16
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.3-7.16

Then, create a pull request where the base branch is 4.3-7.16 and the compare/head branch is backport-4758-to-4.3-7.16.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2022

The backport to 4.3-1.2-wzd failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.3-1.2-wzd 4.3-1.2-wzd
# Navigate to the new working tree
cd .worktrees/backport-4.3-1.2-wzd
# Create a new branch
git switch --create backport-4758-to-4.3-1.2-wzd
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 34c3fae84fe27d41330777996ee4b53c6d43e66f
# Push it to GitHub
git push --set-upstream origin backport-4758-to-4.3-1.2-wzd
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.3-1.2-wzd

Then, create a pull request where the base branch is 4.3-1.2-wzd and the compare/head branch is backport-4758-to-4.3-1.2-wzd.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2022

The backport to 4.4-7.16 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.4-7.16 4.4-7.16
# Navigate to the new working tree
cd .worktrees/backport-4.4-7.16
# Create a new branch
git switch --create backport-4758-to-4.4-7.16
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 34c3fae84fe27d41330777996ee4b53c6d43e66f
# Push it to GitHub
git push --set-upstream origin backport-4758-to-4.4-7.16
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.4-7.16

Then, create a pull request where the base branch is 4.4-7.16 and the compare/head branch is backport-4758-to-4.4-7.16.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2022

The backport to 4.3-7.10 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.3-7.10 4.3-7.10
# Navigate to the new working tree
cd .worktrees/backport-4.3-7.10
# Create a new branch
git switch --create backport-4758-to-4.3-7.10
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 34c3fae84fe27d41330777996ee4b53c6d43e66f
# Push it to GitHub
git push --set-upstream origin backport-4758-to-4.3-7.10
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.3-7.10

Then, create a pull request where the base branch is 4.3-7.10 and the compare/head branch is backport-4758-to-4.3-7.10.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2022

The backport to 4.4-7.10 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.4-7.10 4.4-7.10
# Navigate to the new working tree
cd .worktrees/backport-4.4-7.10
# Create a new branch
git switch --create backport-4758-to-4.4-7.10
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 34c3fae84fe27d41330777996ee4b53c6d43e66f
# Push it to GitHub
git push --set-upstream origin backport-4758-to-4.4-7.10
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.4-7.10

Then, create a pull request where the base branch is 4.4-7.10 and the compare/head branch is backport-4758-to-4.4-7.10.

Tostti added a commit that referenced this pull request Nov 8, 2022
* create service

* Improve service functionality

* add timeout handling

* Improve code quality

* Fix issue that caused infinite loop

* separate interceptor initialization

* add interceptor to plugin start

* fix double reload and add abort

* Add function to disable requests externally

* Add auth validation on server to disable requests

* Update changelog

* Add missing parameters verification

* Add missing parameter validation

* Add reload to interceptor

* Change structure of code

* Implement new service

* Fix bug

* Fix errors

* Create unit tests

* Fix bad reference to previous PR in changelog

* Add missing previous change in changelog

(cherry picked from commit 34c3fae)
Tostti added a commit that referenced this pull request Nov 8, 2022
* create service

* Improve service functionality

* add timeout handling

* Improve code quality

* Fix issue that caused infinite loop

* separate interceptor initialization

* add interceptor to plugin start

* fix double reload and add abort

* Add function to disable requests externally

* Add auth validation on server to disable requests

* Update changelog

* Add missing parameters verification

* Add missing parameter validation

* Add reload to interceptor

* Change structure of code

* Implement new service

* Fix bug

* Fix errors

* Create unit tests

* Fix bad reference to previous PR in changelog

* Add missing previous change in changelog

(cherry picked from commit 34c3fae)
Tostti added a commit that referenced this pull request Nov 8, 2022
* create service

* Improve service functionality

* add timeout handling

* Improve code quality

* Fix issue that caused infinite loop

* separate interceptor initialization

* add interceptor to plugin start

* fix double reload and add abort

* Add function to disable requests externally

* Add auth validation on server to disable requests

* Update changelog

* Add missing parameters verification

* Add missing parameter validation

* Add reload to interceptor

* Change structure of code

* Implement new service

* Fix bug

* Fix errors

* Create unit tests

* Fix bad reference to previous PR in changelog

* Add missing previous change in changelog

(cherry picked from commit 34c3fae)
Tostti added a commit that referenced this pull request Nov 8, 2022
* create service

* Improve service functionality

* add timeout handling

* Improve code quality

* Fix issue that caused infinite loop

* separate interceptor initialization

* add interceptor to plugin start

* fix double reload and add abort

* Add function to disable requests externally

* Add auth validation on server to disable requests

* Update changelog

* Add missing parameters verification

* Add missing parameter validation

* Add reload to interceptor

* Change structure of code

* Implement new service

* Fix bug

* Fix errors

* Create unit tests

* Fix bad reference to previous PR in changelog

* Add missing previous change in changelog

(cherry picked from commit 34c3fae)
Tostti added a commit that referenced this pull request Nov 8, 2022
* create service

* Improve service functionality

* add timeout handling

* Improve code quality

* Fix issue that caused infinite loop

* separate interceptor initialization

* add interceptor to plugin start

* fix double reload and add abort

* Add function to disable requests externally

* Add auth validation on server to disable requests

* Update changelog

* Add missing parameters verification

* Add missing parameter validation

* Add reload to interceptor

* Change structure of code

* Implement new service

* Fix bug

* Fix errors

* Create unit tests

* Fix bad reference to previous PR in changelog

* Add missing previous change in changelog

(cherry picked from commit 34c3fae)
AlexRuiz7 added a commit that referenced this pull request Nov 8, 2022
Tostti pushed a commit that referenced this pull request Nov 8, 2022
Revert "Add centralized request service (#4758)"

This reverts commit 34c3fae.
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 this pull request may close these issues.

4 participants