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

Use password message from /dashboardsinfo #1503

Merged
merged 7 commits into from
Jul 11, 2023

Conversation

cwperks
Copy link
Member

@cwperks cwperks commented Jul 6, 2023

Description

Companion Security PR: opensearch-project/security#2949

This PR uses the message from /_plugins/_security/dashboardsinfo to get the password message from the backend if its configured in opensearch.yml. If the setting is not set, the backend will return the default.

Category

[Enhancement, New feature, Bug fix, Test fix, Refactoring, Maintenance, Documentation]

Bug fix

Issues Resolved

#1501

Testing

Jest tests and manual dashboard testing of both password reset and password edit

Check List

  • New functionality includes testing
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Craig Perkins <cwperx@amazon.com>
cwperks added 2 commits July 6, 2023 10:09
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
@@ -43,7 +62,7 @@ export function PasswordEditPanel(props: {

return (
<>
<FormRow headerText="Password" helpText={PASSWORD_INSTRUCTION}>
<FormRow data-test-subj="password-form-row" headerText="Password" helpText={passwordHelpText}>
Copy link
Member

Choose a reason for hiding this comment

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

qq. Why add data-test-subj?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed that, I was trying to write a test to verify the text after a state update in the password-edit-panel but opted instead to assert that setState with the custom message had been called.


beforeEach(() => {
useEffect.mockImplementationOnce((f) => f());
useState.mockImplementation((initialValue) => [initialValue, setState]);
(getDashboardsInfo as jest.Mock).mockImplementation(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Is this still need even though it is mocked above?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not, I removed this and also removed creating the shallow component in beforeEach and moved it into each individual test. The first test needs mount(...) instead of shallow(...) to test the logic in React.useEffect(...)

it('renders', (done) => {
(getDashboardsInfo as jest.Mock).mockImplementation(() => {
return mockDashboardsInfo;
});
Copy link
Member

Choose a reason for hiding this comment

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

Is this mock needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like this was made redundant by the block above:

jest.mock('../../../../utils/dashboards-info-utils', () => ({
  getDashboardsInfo: jest.fn().mockImplementation(() => {
    return mockDashboardsInfo;
  }),
}));

I removed this redundant mock. Thanks for pointing that out.

cwperks added 2 commits July 6, 2023 10:29
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Merging #1503 (c3db9d4) into main (5fd8018) will decrease coverage by 0.06%.
The diff coverage is 57.14%.

@@            Coverage Diff             @@
##             main    #1503      +/-   ##
==========================================
- Coverage   66.11%   66.06%   -0.06%     
==========================================
  Files          93       93              
  Lines        2314     2328      +14     
  Branches      310      310              
==========================================
+ Hits         1530     1538       +8     
- Misses        716      722       +6     
  Partials       68       68              
Impacted Files Coverage Δ
...n/panels/internal-user-edit/internal-user-edit.tsx 80.48% <ø> (ø)
public/apps/account/password-reset-panel.tsx 84.61% <28.57%> (-12.26%) ⬇️
...c/apps/configuration/utils/password-edit-panel.tsx 95.23% <85.71%> (-4.77%) ⬇️

@cwperks cwperks added the backport 2.x backport to 2.x branch label Jul 6, 2023
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Copy link
Collaborator

@RyanL1997 RyanL1997 left a comment

Choose a reason for hiding this comment

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

Hi @cwperks, thank you for this work and it looks good to me in general.

@@ -32,6 +32,7 @@ import { logout, updateNewPassword } from './utils';
import { PASSWORD_INSTRUCTION } from '../apps-constants';
Copy link
Collaborator

Choose a reason for hiding this comment

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

For this PASSWORD_INSTRUCTION, should we also update it so that it has the new password rules that introduced by the strong password validation feature?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just like this password_validation_error_message :

'Password must be minimum 5 characters long and must contain at least one uppercase letter, one lowercase letter, one digit, and one special character.'

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point and needs to be updated on the backend as well. I'll adjust it according to the description on the PR that introduced password strength: opensearch-project/security#2557

plugins.security.restapi.password_min_length - minimum password length, default and minimum is 8

Copy link
Member Author

Choose a reason for hiding this comment

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

This is already properly set: https://github.com/opensearch-project/security-dashboards-plugin/blob/main/public/apps/apps-constants.tsx

Note: This default is duplicated and the frontend and backend. I decided to keep the value in the frontend, but it could certainly be removed from the frontend codebase in favor of just keeping a single reference on the backend.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's do this as a follow up PR to unblock your change.

@cwperks cwperks merged commit f774ae4 into opensearch-project:main Jul 11, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 11, 2023
* Use password message from /dashboardsinfo

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Run eslint --fix

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused attribute

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Clean up test

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove redundant mock

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Removed TODO messages

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>
(cherry picked from commit f774ae4)
cwperks added a commit that referenced this pull request Jul 11, 2023
* Use password message from /dashboardsinfo

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Run eslint --fix

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused attribute

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Clean up test

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove redundant mock

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Removed TODO messages

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>
(cherry picked from commit f774ae4)

Co-authored-by: Craig Perkins <cwperx@amazon.com>
samuelcostae pushed a commit to samuelcostae/security-dashboards-plugin that referenced this pull request Aug 10, 2023
* Use password message from /dashboardsinfo

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Run eslint --fix

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove unused attribute

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Clean up test

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Remove redundant mock

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Removed TODO messages

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Sam <samuel.costa@eliatra.com>
@stephen-crawford
Copy link
Contributor

This went in the 2.9 release not 2.10 so removing the label.

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

Successfully merging this pull request may close these issues.

5 participants