Skip to content

Commit

Permalink
Merge branch '3.0' into 3
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Mar 4, 2025
2 parents 98f0553 + d9fae02 commit 6b3cedc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ function SudoModePasswordField(props) {
const headers = {
'X-SecurityID': Config.get('SecurityID'),
};
const responseJson = await fetcher(data, headers);
if (responseJson.result) {
onSuccess();
} else {
setResponseMessage(responseJson.message);
}
fetcher(data, headers)
.then(() => onSuccess())
.catch(async (err) => {
const responseJson = await err.response.json();
setResponseMessage(responseJson.message);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,29 @@ window.ss.config = {
};

let doResolve;
let doReject;

beforeEach(() => {
doResolve = undefined;
doReject = undefined;
});

function createJsonError(message) {
return {
response: {
json: () => ({
result: false,
message
}),
},
};
}

jest.mock('lib/Backend', () => ({
createEndpointFetcher: () => () => (
new Promise((resolve) => {
new Promise((resolve, reject) => {
doResolve = resolve;
doReject = reject;
})
)
}));
Expand Down Expand Up @@ -68,10 +86,7 @@ test('SudoModePasswordField should show a message on failure', async () => {
passwordField.value = 'password';
const verifyButton = await screen.findByText('Verify');
fireEvent.click(verifyButton);
doResolve({
result: false,
message: 'A big failure'
});
await doReject(createJsonError('A big failure'));
const message = await screen.findByText('A big failure');
expect(message).not.toBeNull();
expect(onSuccess).not.toBeCalled();
Expand Down
4 changes: 1 addition & 3 deletions code/SudoModeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,20 @@ public function activate(HTTPRequest $request): HTTPResponse

if (!SecurityToken::inst()->checkRequest($request)) {
return $this->jsonResponse([
'result' => false,
'message' => _t(__CLASS__ . '.TIMEOUT', 'Session timed out, please refresh and try again.'),
], 403);
}

// Validate password
if (!$this->checkPassword($request)) {
return $this->jsonResponse([
'result' => false,
'message' => _t(__CLASS__ . '.INVALID', 'Incorrect password'),
], 401);
}

// Activate sudo mode and return successful result
$this->getSudoModeService()->activate($request->getSession());
return $this->jsonResponse(['result' => true]);
return $this->jsonResponse([]);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/behat/features/form-sudo-mode.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Feature: Form sudo mode
# CMS profile
When I go to "/admin/myprofile"
Then I should see "Verify to continue"
And I should see a "#action_save[readonly]" element
And I should see a "#Form_EditForm_action_save[readonly]" element

# Security admin - members
When I go to "/admin/security"
Expand Down Expand Up @@ -65,7 +65,7 @@ Feature: Form sudo mode
And I fill in "SudoModePassword" with "incorrect-password"
And I click on the ".sudo-mode-password-field__verify-button" element
Then I should see "Incorrect password"
And I should see a "#action_save[readonly]" element
And I should see a "#Form_EditForm_action_save[readonly]" element

Scenario: Sensitive data can be edited after activating sudo mode

Expand All @@ -75,7 +75,7 @@ Feature: Form sudo mode
And I fill in "SudoModePassword" with "Secret!123"
And I click on the ".sudo-mode-password-field__verify-button" element
And I wait for 2 seconds
Then I should not see a "#action_save[readonly]" element
Then I should not see a "#Form_EditForm_action_save[readonly]" element

# Security admin - members
When I go to "/admin/security"
Expand Down
3 changes: 0 additions & 3 deletions tests/php/SudoModeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public function testActivateFailsWithIncorrectPassword()

$this->assertSame(401, $response->getStatusCode());
$result = json_decode((string) $response->getBody(), true);
$this->assertFalse($result['result'], 'Should have failed with incorrect password');
$this->assertEquals('Incorrect password', $result['message']);
}

Expand All @@ -103,7 +102,6 @@ public function testActivateSudoModeWithValidCredentials()

$this->assertSame(200, $activateResponse->getStatusCode());
$result = json_decode((string) $activateResponse->getBody(), true);
$this->assertTrue($result['result'], 'Should have activated sudo mode');

$checkResponse = $this->get(SudoModeController::singleton()->Link('check'));
$this->assertSame(200, $checkResponse->getStatusCode());
Expand All @@ -128,7 +126,6 @@ public function testActivateChecksCSRFToken()

$this->assertSame(403, $activateResponse->getStatusCode());
$result = json_decode((string) $activateResponse->getBody(), true);
$this->assertFalse($result['result'], 'Should have failed on CSRF token validation');
$this->assertSame($result['message'], 'Session timed out, please refresh and try again.');
}

Expand Down

0 comments on commit 6b3cedc

Please # to comment.