Skip to content

Commit

Permalink
minor requested formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
YSaxon committed Oct 17, 2023
1 parent ebb3786 commit 1a6d699
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Sandbox/SecurityPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function checkMethodAllowed($obj, $method)
}

if (!$allowed) {
$class = \get_class($obj);
$class = $obj::class;
throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method);
}
}
Expand All @@ -119,7 +119,7 @@ public function checkPropertyAllowed($obj, $property)
}

if (!$allowed) {
$class = \get_class($obj);
$class = $obj::class;
throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sandbox/SourcePolicyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ interface SourcePolicyInterface
* @param Source $source
*
*/
public function enableSandbox(Source $source = null) : bool;
public function enableSandbox(Source $source = null): bool;
}
25 changes: 14 additions & 11 deletions tests/Extension/SandboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testSandboxGloballyFalseUnallowedFilterWithIncludeTemplateFromSt
$twig->load('1_basic2_include_template_from_string_sandboxed')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called');
} catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError');
$this->assertInstanceOf(SecurityNotAllowedFilterError::class, $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError');
$this->assertEquals('upper', $e->getFilterName(), 'Exception should be raised on the "upper" filter');
}
}
Expand All @@ -120,7 +120,7 @@ public function testSandboxGloballyTrueUnallowedFilterWithIncludeTemplateFromStr
$twig->load('1_basic2_include_template_from_string_sandboxed')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called');
} catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError');
$this->assertInstanceOf(SecurityNotAllowedFilterError::class, $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError');
$this->assertEquals('upper', $e->getFilterName(), 'Exception should be raised on the "upper" filter');
}
}
Expand All @@ -140,7 +140,7 @@ public function testSandboxGloballyTrueUnallowedFilterWithIncludeTemplateFromStr
$twig->load('1_basic2_include_template_from_string')->render(self::$params);
$this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called');
} catch (SecurityError $e) {
$this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError');
$this->assertInstanceOf(SecurityNotAllowedFilterError::class, $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError');
$this->assertEquals('upper', $e->getFilterName(), 'Exception should be raised on the "upper" filter');
}
}
Expand Down Expand Up @@ -389,7 +389,7 @@ public function testSandboxDisabledAfterIncludeFunctionError()

public function testSandboxWithNoClosureFilter()
{
$this->expectException('\Twig\Error\RuntimeError');
$this->expectException(\Twig\Error\RuntimeError::class);
$this->expectExceptionMessage('The callable passed to the "filter" filter must be a Closure in sandbox mode in "index" at line 1.');

$twig = $this->getEnvironment(true, ['autoescape' => 'html'], ['index' => <<<EOF
Expand Down Expand Up @@ -425,8 +425,9 @@ public function testSandboxSourcePolicyEnableReturningFalse()
$twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class() implements \Twig\Sandbox\SourcePolicyInterface {
public function enableSandbox($source): bool
{
return $source->getName() != '1_basic';
}});
return '1_basic' != $source->getName();
}
});
$this->assertEquals('FOO', $twig->load('1_basic')->render(self::$params));
}

Expand All @@ -435,8 +436,9 @@ public function testSandboxSourcePolicyEnableReturningTrue()
$twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class() implements \Twig\Sandbox\SourcePolicyInterface {
public function enableSandbox($source): bool
{
return $source->getName() === '1_basic';
}});
return '1_basic' === $source->getName();
}
});
$this->expectException(SecurityError::class);
$twig->load('1_basic')->render([]);
}
Expand All @@ -447,9 +449,10 @@ public function testSandboxSourcePolicyFalseDoesntOverrideOtherEnables()
public function enableSandbox($source): bool
{
return false;
}});
$this->expectException(SecurityError::class);
$twig->load('1_basic')->render([]);
}
});
$this->expectException(SecurityError::class);
$twig->load('1_basic')->render([]);
}
}

Expand Down

0 comments on commit 1a6d699

Please sign in to comment.