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

NEW Add ActivateSudoModeServiceExtension #298

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,15 @@ for example to cast any argument matching the `\d` regex into an actual PHP inte
[strtotime()](http://www.php.net/manual/en/datetime.formats.relative.php). Example: "the datetime of 2 days ago" might
return "2013-10-10 23:00:00" if its currently the 12th of October 2013.

### Disabling sudo mode

The activate mode sudo extension will disable sudo mode so that you do not need to re-enter your password for any
data protected by sudo mode.

```cucumber
Given I add an extension "SilverStripe\BehatExtension\Extensions\ActivateSudoModeServiceExtension" to the "SilverStripe\Security\SudoMode\SudoModeService" class
```

## Useful resources

* [Silverstripe CMS architecture](https://docs.silverstripe.org/sapphire/en/trunk/reference/cms-architecture)
Expand Down
22 changes: 22 additions & 0 deletions src/Extensions/ActivateSudoModeServiceExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace SilverStripe\BehatExtension\Extensions;

use SilverStripe\Control\Session;
use SilverStripe\Forms\Form;
use SilverStripe\Core\Extension;

/**
* Extension that will make it as if sudo mode is active for the current session
* Intended to be used with behat tests so that there is no need to enter a password
* when testing forms that require sudo mode
*
* @extends Extension<Form>
*/
class ActivateSudoModeServiceExtension extends Extension
{
public function updateCheck(bool &$active, Session $session)
{
$active = true;
}
}