Skip to content

Commit

Permalink
NEW Add ActivateSudoModeServiceExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Feb 18, 2025
1 parent 5788611 commit 8880fa7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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 allows 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;
}
}

0 comments on commit 8880fa7

Please sign in to comment.