mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-25 00:48:45 +00:00
test(cypress/users): add automatic reset password test (#9515)
This commit is contained in:
parent
89c7059ce9
commit
4efa46f8c9
@ -98,8 +98,8 @@ export default function UserListItem({ user, canManageUserCredentials, selectRol
|
||||
<div>
|
||||
<Typography.Text>{displayName}</Typography.Text>
|
||||
</div>
|
||||
<div>
|
||||
<Typography.Text type="secondary">{user.username}</Typography.Text>
|
||||
<div data-testid={`email-${shouldShowPasswordReset ? 'native' : 'non-native'}`}>
|
||||
<Typography.Text type="secondary" >{user.username}</Typography.Text>
|
||||
</div>
|
||||
</div>
|
||||
{userStatus && (
|
||||
@ -121,8 +121,12 @@ export default function UserListItem({ user, canManageUserCredentials, selectRol
|
||||
trigger={['click']}
|
||||
overlay={
|
||||
<Menu>
|
||||
<Menu.Item disabled={!shouldShowPasswordReset} onClick={() => setIsViewingResetToken(true)}>
|
||||
<UnlockOutlined /> Reset user password
|
||||
<Menu.Item
|
||||
disabled={!shouldShowPasswordReset}
|
||||
onClick={() => setIsViewingResetToken(true)}
|
||||
data-testid="reset-menu-item"
|
||||
>
|
||||
<UnlockOutlined data-testid="resetButton" /> Reset user password
|
||||
</Menu.Item>
|
||||
<Menu.Item onClick={onDeleteEntity}>
|
||||
<DeleteOutlined /> Delete
|
||||
@ -130,7 +134,10 @@ export default function UserListItem({ user, canManageUserCredentials, selectRol
|
||||
</Menu>
|
||||
}
|
||||
>
|
||||
<MenuIcon fontSize={20} />
|
||||
<MenuIcon
|
||||
fontSize={20}
|
||||
data-testid={`userItem-${shouldShowPasswordReset ? 'native' : 'non-native'}`}
|
||||
/>
|
||||
</Dropdown>
|
||||
</ButtonGroup>
|
||||
<ViewResetTokenModal
|
||||
|
||||
@ -114,7 +114,12 @@ export default function ViewResetTokenModal({ visible, userUrn, username, onClos
|
||||
<ModalSectionParagraph>
|
||||
Generate a new reset link! Note, any old links will <b>cease to be active</b>.
|
||||
</ModalSectionParagraph>
|
||||
<CreateResetTokenButton onClick={createNativeUserResetToken} size="small" type="text">
|
||||
<CreateResetTokenButton
|
||||
onClick={createNativeUserResetToken}
|
||||
size="small"
|
||||
type="text"
|
||||
data-testid="refreshButton"
|
||||
>
|
||||
<RedoOutlined style={{}} />
|
||||
</CreateResetTokenButton>
|
||||
</ModalSection>
|
||||
|
||||
@ -1,47 +1,104 @@
|
||||
const tryToSignUp = () => {
|
||||
let number = Math.floor(Math.random() * 100000);
|
||||
let name = `Example Name ${number}`;
|
||||
cy.enterTextInTestId("email", `example${number}@example.com`);
|
||||
cy.enterTextInTestId("name", name);
|
||||
cy.enterTextInTestId("password", "Example password");
|
||||
cy.enterTextInTestId("confirmPassword", "Example password");
|
||||
let number = Math.floor(Math.random() * 100000);
|
||||
let name = `Example Name ${number}`;
|
||||
let email = `example${number}@example.com`;
|
||||
cy.enterTextInTestId("email", email);
|
||||
cy.enterTextInTestId("name", name);
|
||||
cy.enterTextInTestId("password", "Example password");
|
||||
cy.enterTextInTestId("confirmPassword", "Example password");
|
||||
|
||||
cy.mouseover("#title").click();
|
||||
cy.waitTextVisible("Other").click();
|
||||
cy.mouseover("#title").click();
|
||||
cy.waitTextVisible("Other").click();
|
||||
|
||||
cy.get("[type=submit]").click();
|
||||
return name;
|
||||
cy.get("[type=submit]").click();
|
||||
return { name, email };
|
||||
};
|
||||
|
||||
describe("add_user", () => {
|
||||
it("go to user link and invite a user", () => {
|
||||
cy.login();
|
||||
let registeredEmail = "";
|
||||
it("go to user link and invite a user", () => {
|
||||
cy.login();
|
||||
|
||||
cy.visit("/settings/identities/users");
|
||||
cy.waitTextVisible("Invite Users");
|
||||
|
||||
cy.clickOptionWithText("Invite Users");
|
||||
|
||||
cy.waitTextVisible(/signup\?invite_token=\w{32}/)
|
||||
.then(($elem) => {
|
||||
const inviteLink = $elem.text();
|
||||
cy.log(inviteLink);
|
||||
cy.visit("/settings/identities/users");
|
||||
cy.waitTextVisible("Invite Users");
|
||||
cy.logout();
|
||||
cy.visit(inviteLink);
|
||||
const { name, email } = tryToSignUp();
|
||||
registeredEmail = email;
|
||||
cy.waitTextVisible("Welcome to DataHub");
|
||||
cy.hideOnboardingTour();
|
||||
cy.waitTextVisible(name);
|
||||
})
|
||||
.then(() => {
|
||||
cy.logout();
|
||||
cy.visit("/signup?invite_token=bad_token");
|
||||
tryToSignUp();
|
||||
cy.waitTextVisible("Failed to log in! An unexpected error occurred.");
|
||||
});
|
||||
});
|
||||
|
||||
cy.clickOptionWithText("Invite Users");
|
||||
it("Verify you can’t generate a reset password link for a non-native user", () => {
|
||||
cy.login();
|
||||
cy.visit("/settings/identities/users");
|
||||
cy.waitTextVisible("Invite Users");
|
||||
cy.get("[data-testid=userItem-non-native]").first().click();
|
||||
cy.get('[data-testid="reset-menu-item"]').should(
|
||||
"have.attr",
|
||||
"aria-disabled",
|
||||
"true"
|
||||
);
|
||||
});
|
||||
|
||||
cy.waitTextVisible(/signup\?invite_token=\w{32}/).then(($elem) => {
|
||||
const inviteLink = $elem.text();
|
||||
cy.log(inviteLink);
|
||||
cy.visit("/settings/identities/users");
|
||||
cy.logout();
|
||||
cy.visit(inviteLink);
|
||||
let name = tryToSignUp();
|
||||
cy.waitTextVisible("Welcome to DataHub");
|
||||
cy.hideOnboardingTour();
|
||||
cy.waitTextVisible(name);
|
||||
}).then(() => {
|
||||
cy.logout();
|
||||
cy.visit("/signup?invite_token=bad_token");
|
||||
tryToSignUp();
|
||||
cy.waitTextVisible("Failed to log in! An unexpected error occurred.");
|
||||
});
|
||||
it("Generate a reset password link for a native user", () => {
|
||||
cy.login();
|
||||
cy.visit("/settings/identities/users");
|
||||
cy.waitTextVisible("Invite Users");
|
||||
cy.get(`[data-testid="email-native"]`)
|
||||
.contains(registeredEmail)
|
||||
.should("exist")
|
||||
.parents(".ant-list-item")
|
||||
.find('[data-testid="userItem-native"]')
|
||||
.should("be.visible")
|
||||
.click();
|
||||
|
||||
cy.get("[data-testid=resetButton]").first().click();
|
||||
cy.get("[data-testid=refreshButton]").click();
|
||||
cy.waitTextVisible("Generated new link to reset credentials");
|
||||
|
||||
cy.window().then((win) => {
|
||||
cy.stub(win, "prompt");
|
||||
});
|
||||
});
|
||||
cy.get(".ant-typography-copy").should("be.visible").click();
|
||||
cy.get(".ant-modal-close").should("be.visible").click();
|
||||
|
||||
// Verify you can’t generate a reset password link for a non-native user (root, for example)
|
||||
// Generate a reset password link for a native user
|
||||
// Log out, then verify that using a bad reset token in the URL doesn’t allow you to reset password
|
||||
// Use the correct reset link to reset native user credentials
|
||||
cy.waitTextVisible(/reset\?reset_token=\w{32}/)
|
||||
.then(($elem) => {
|
||||
const inviteLink = $elem.text();
|
||||
cy.logout();
|
||||
cy.visit(inviteLink);
|
||||
cy.enterTextInTestId("email", registeredEmail);
|
||||
cy.enterTextInTestId("password", "Example Reset Password");
|
||||
cy.enterTextInTestId("confirmPassword", "Example Reset Password");
|
||||
cy.get("[type=submit]").click();
|
||||
cy.waitTextVisible("Welcome back");
|
||||
cy.hideOnboardingTour();
|
||||
})
|
||||
.then(() => {
|
||||
cy.logout();
|
||||
cy.visit("/reset?reset_token=bad_token");
|
||||
cy.enterTextInTestId("email", registeredEmail);
|
||||
cy.enterTextInTestId("password", "Example Reset Password");
|
||||
cy.enterTextInTestId("confirmPassword", "Example Reset Password");
|
||||
cy.get("[type=submit]").click();
|
||||
cy.waitTextVisible("Failed to log in!");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user