summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Controller/LostControllerTest.php12
-rw-r--r--tests/Settings/Mailer/NewUserMailHelperTest.php224
-rw-r--r--tests/lib/AppConfigTest.php2
-rw-r--r--tests/lib/AppFramework/Middleware/Security/CSPMiddlewareTest.php149
-rw-r--r--tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php97
-rw-r--r--tests/lib/Files/Cache/CacheTest.php70
-rw-r--r--tests/lib/Files/Node/FolderTest.php51
-rw-r--r--tests/lib/Lockdown/Filesystem/NullCacheTest.php4
8 files changed, 384 insertions, 225 deletions
diff --git a/tests/Core/Controller/LostControllerTest.php b/tests/Core/Controller/LostControllerTest.php
index 8500819a9ca..41f3bb03f02 100644
--- a/tests/Core/Controller/LostControllerTest.php
+++ b/tests/Core/Controller/LostControllerTest.php
@@ -275,8 +275,10 @@ class LostControllerTest extends \Test\TestCase {
array(false, $nonExistingUser)
)));
- $this->logger->expects($this->exactly(2))
+ $this->logger->expects($this->exactly(0))
->method('logException');
+ $this->logger->expects($this->exactly(2))
+ ->method('warning');
$this->userManager
->method('getByEmail')
@@ -722,8 +724,10 @@ class LostControllerTest extends \Test\TestCase {
->with('ExistingUser')
->willReturn($user);
- $this->logger->expects($this->exactly(1))
+ $this->logger->expects($this->exactly(0))
->method('logException');
+ $this->logger->expects($this->once())
+ ->method('warning');
$response = $this->lostController->email('ExistingUser');
$expectedResponse = new JSONResponse(['status' => 'success']);
@@ -807,8 +811,10 @@ class LostControllerTest extends \Test\TestCase {
->method('getByEmail')
->willReturn([$user1, $user2]);
- $this->logger->expects($this->exactly(1))
+ $this->logger->expects($this->exactly(0))
->method('logException');
+ $this->logger->expects($this->once())
+ ->method('warning');
// request password reset for test@example.com
$response = $this->lostController->email('test@example.com');
diff --git a/tests/Settings/Mailer/NewUserMailHelperTest.php b/tests/Settings/Mailer/NewUserMailHelperTest.php
index 5eccc5bc9f4..f29da7fbfde 100644
--- a/tests/Settings/Mailer/NewUserMailHelperTest.php
+++ b/tests/Settings/Mailer/NewUserMailHelperTest.php
@@ -610,6 +610,230 @@ EOF;
$this->assertSame('OC\Mail\EMailTemplate', get_class($result));
}
+ public function testGenerateTemplateWithoutUserId() {
+ $this->urlGenerator
+ ->expects($this->at(0))
+ ->method('getAbsoluteURL')
+ ->with('/')
+ ->willReturn('https://example.com/');
+
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
+ $user = $this->createMock(IUser::class);
+ $user
+ ->expects($this->any())
+ ->method('getDisplayName')
+ ->willReturn('John Doe');
+ $user
+ ->expects($this->any())
+ ->method('getUID')
+ ->willReturn('john');
+ $user
+ ->expects($this->atLeastOnce())
+ ->method('getBackendClassName')
+ ->willReturn('LDAP');
+ $this->defaults
+ ->expects($this->any())
+ ->method('getName')
+ ->willReturn('TestCloud');
+ $this->defaults
+ ->expects($this->any())
+ ->method('getTextColorPrimary')
+ ->willReturn('#ffffff');
+
+ $expectedHtmlBody = <<<EOF
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important">
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta name="viewport" content="width=device-width">
+ <title></title>
+ <style type="text/css">@media only screen{html{min-height:100%;background:#F5F5F5}}@media only screen and (max-width:610px){table.body img{width:auto;height:auto}table.body center{min-width:0!important}table.body .container{width:95%!important}table.body .columns{height:auto!important;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box;padding-left:30px!important;padding-right:30px!important}th.small-12{display:inline-block!important;width:100%!important}table.menu{width:100%!important}table.menu td,table.menu th{width:auto!important;display:inline-block!important}table.menu.vertical td,table.menu.vertical th{display:block!important}table.menu[align=center]{width:auto!important}}</style>
+</head>
+<body style="-moz-box-sizing:border-box;-ms-text-size-adjust:100%;-webkit-box-sizing:border-box;-webkit-font-smoothing:antialiased;-webkit-text-size-adjust:100%;Margin:0;background:#f3f3f3!important;box-sizing:border-box;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;min-width:100%;padding:0;text-align:left;width:100%!important">
+ <span class="preheader" style="color:#F5F5F5;display:none!important;font-size:1px;line-height:1px;max-height:0;max-width:0;mso-hide:all!important;opacity:0;overflow:hidden;visibility:hidden">
+ </span>
+ <table class="body" style="-webkit-font-smoothing:antialiased;Margin:0;background:#f3f3f3!important;border-collapse:collapse;border-spacing:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;height:100%;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="center" align="center" valign="top" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <center data-parsed="" style="min-width:580px;width:100%"><table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table align="center" class="container" style="Margin:0 auto;background:0 0;border-collapse:collapse;border-spacing:0;margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table class="row collapse" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <center data-parsed="" style="min-width:580px;width:100%">
+ <img class="logo float-center" src="" alt="TestCloud" align="center" style="-ms-interpolation-mode:bicubic;Margin:0 auto;clear:both;display:block;float:none;margin:0 auto;outline:0;text-align:center;text-decoration:none" height="50">
+ </center>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="80px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:80px;font-weight:400;hyphens:auto;line-height:80px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table><table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <h1 class="text-center" style="Margin:0;Margin-bottom:10px;color:inherit;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:center;word-wrap:normal">Welcome aboard John Doe</h1>
+ </td>
+ </tr>
+ </tbody>
+</table>
+<table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="40px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:40px;font-weight:400;hyphens:auto;line-height:40px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table><table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table align="center" class="container has-shadow" style="Margin:0 auto;background:#fefefe;border-collapse:collapse;border-spacing:0;box-shadow:0 1px 2px 0 rgba(0,0,0,.2),0 1px 3px 0 rgba(0,0,0,.1);margin:0 auto;padding:0;text-align:inherit;vertical-align:top;width:580px">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+ </table><table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+ <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;text-align:left">Welcome to your TestCloud account, you can add, protect, and share your data.</p>
+ </th>
+ <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+ </tr>
+ </table>
+ </th>
+ </tr>
+ </tbody>
+</table><table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="50px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:50px;font-weight:400;hyphens:auto;line-height:50px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table>
+<table align="center" class="row btn-group" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th class="small-12 large-12 columns first last" style="Margin:0 auto;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0 auto;padding:0;padding-bottom:30px;padding-left:30px;padding-right:30px;text-align:left;width:550px">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <th style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
+ <center data-parsed="" style="min-width:490px;width:100%">
+ <table class="button btn default primary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;margin-right:15px;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto;background:;background-color:;color:#fefefe;">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border:0 solid ;border-collapse:collapse!important;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://example.com/" style="Margin:0;border:0 solid ;border-radius:2px;color:#ffffff;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;padding:10px 25px 10px 25px;text-align:left;outline:1px solid #ffffff;text-decoration:none">Go to TestCloud</a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ <table class="button btn default secondary float-center" style="Margin:0 0 30px 0;border-collapse:collapse;border-spacing:0;display:inline-block;float:none;margin:0 0 30px 0;max-height:40px;max-width:200px;padding:0;text-align:center;vertical-align:top;width:auto">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;background:#777;border:0 solid #777;border-collapse:collapse!important;color:#fefefe;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <a href="https://nextcloud.com/install/#install-clients" style="Margin:0;background-color:#fff;border:0 solid #777;border-radius:2px;color:#6C6C6C!important;display:inline-block;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:regular;line-height:1.3;margin:0;outline:1px solid #CBCBCB;padding:10px 25px 10px 25px;text-align:left;text-decoration:none">Install Client</a>
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+ </table>
+ </center>
+ </th>
+ <th class="expander" style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0!important;text-align:left;visibility:hidden;width:0"></th>
+ </tr>
+ </table>
+ </th>
+ </tr>
+ </tbody>
+</table>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </td>
+ </tr>
+</table><table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="60px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:60px;font-weight:400;hyphens:auto;line-height:60px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+</table>
+<table align="center" class="wrapper footer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">
+ <center data-parsed="" style="min-width:580px;width:100%">
+ <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%">
+ <tbody>
+ <tr style="padding:0;text-align:left;vertical-align:top">
+ <td height="15px" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:15px;font-weight:400;hyphens:auto;line-height:15px;margin:0;mso-line-height-rule:exactly;padding:0;text-align:left;vertical-align:top;word-wrap:break-word">&#xA0;</td>
+ </tr>
+ </tbody>
+ </table>
+ <p class="text-center float-center" align="center" style="Margin:0;Margin-bottom:10px;color:#C8C8C8;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:12px;font-weight:400;line-height:16px;margin:0;margin-bottom:10px;padding:0;text-align:center">TestCloud - <br>This is an automatically sent email, please do not reply.</p>
+ </center>
+ </td>
+ </tr>
+</table> </center>
+ </td>
+ </tr>
+ </table>
+ <!-- prevent Gmail on iOS font size manipulation -->
+ <div style="display:none;white-space:nowrap;font:15px courier;line-height:0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
+ </body>
+</html>
+EOF;
+ $expectedTextBody = <<<EOF
+Welcome aboard John Doe
+
+Welcome to your TestCloud account, you can add, protect, and share your data.
+
+Go to TestCloud: https://example.com/
+Install Client: https://nextcloud.com/install/#install-clients
+
+
+--
+TestCloud -
+This is an automatically sent email, please do not reply.
+EOF;
+
+ $result = $this->newUserMailHelper->generateTemplate($user, false);
+ $this->assertEquals($expectedHtmlBody, $result->renderHtml());
+ $this->assertEquals($expectedTextBody, $result->renderText());
+ $this->assertSame('OC\Mail\EMailTemplate', get_class($result));
+ }
+
public function testSendMail() {
/** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
$user = $this->createMock(IUser::class);
diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php
index fed929352d3..9456fe4c232 100644
--- a/tests/lib/AppConfigTest.php
+++ b/tests/lib/AppConfigTest.php
@@ -318,12 +318,14 @@ class AppConfigTest extends TestCase {
->with('user_ldap', false)
->willReturn([
'ldap_agent_password' => 'secret',
+ 's42ldap_agent_password' => 'secret',
'ldap_dn' => 'dn',
]);
$values = $config->getFilteredValues('user_ldap');
$this->assertEquals([
'ldap_agent_password' => IConfig::SENSITIVE_VALUE,
+ 's42ldap_agent_password' => IConfig::SENSITIVE_VALUE,
'ldap_dn' => 'dn',
], $values);
}
diff --git a/tests/lib/AppFramework/Middleware/Security/CSPMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/CSPMiddlewareTest.php
new file mode 100644
index 00000000000..9f2b4e399fb
--- /dev/null
+++ b/tests/lib/AppFramework/Middleware/Security/CSPMiddlewareTest.php
@@ -0,0 +1,149 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\AppFramework\Middleware\Security;
+
+use OC\AppFramework\Middleware\Security\CSPMiddleware;
+use OC\Security\CSP\ContentSecurityPolicy;
+use OC\Security\CSP\ContentSecurityPolicyManager;
+use OC\Security\CSP\ContentSecurityPolicyNonceManager;
+use OC\Security\CSRF\CsrfToken;
+use OC\Security\CSRF\CsrfTokenManager;
+use OCP\AppFramework\Controller;
+use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
+use OCP\AppFramework\Http\Response;
+use PHPUnit\Framework\MockObject\MockObject;
+
+class CSPMiddlewareTest extends \Test\TestCase {
+
+ /** @var CSPMiddleware|MockObject */
+ private $middleware;
+ /** @var Controller|MockObject */
+ private $controller;
+ /** @var ContentSecurityPolicyManager|MockObject */
+ private $contentSecurityPolicyManager;
+ /** @var CsrfTokenManager|MockObject */
+ private $csrfTokenManager;
+ /** @var ContentSecurityPolicyNonceManager|MockObject */
+ private $cspNonceManager;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->controller = $this->createMock(Controller::class);
+ $this->contentSecurityPolicyManager = $this->createMock(ContentSecurityPolicyManager::class);
+ $this->csrfTokenManager = $this->createMock(CsrfTokenManager::class);
+ $this->cspNonceManager = $this->createMock(ContentSecurityPolicyNonceManager::class);
+ $this->middleware = new CSPMiddleware(
+ $this->contentSecurityPolicyManager,
+ $this->cspNonceManager,
+ $this->csrfTokenManager
+ );
+ }
+
+ public function testAfterController() {
+ $this->cspNonceManager
+ ->expects($this->once())
+ ->method('browserSupportsCspV3')
+ ->willReturn(false);
+ $response = $this->createMock(Response::class);
+ $defaultPolicy = new ContentSecurityPolicy();
+ $defaultPolicy->addAllowedImageDomain('defaultpolicy');
+ $currentPolicy = new ContentSecurityPolicy();
+ $currentPolicy->addAllowedConnectDomain('currentPolicy');
+ $mergedPolicy = new ContentSecurityPolicy();
+ $mergedPolicy->addAllowedMediaDomain('mergedPolicy');
+ $response
+ ->expects($this->exactly(2))
+ ->method('getContentSecurityPolicy')
+ ->willReturn($currentPolicy);
+ $this->contentSecurityPolicyManager
+ ->expects($this->once())
+ ->method('getDefaultPolicy')
+ ->willReturn($defaultPolicy);
+ $this->contentSecurityPolicyManager
+ ->expects($this->once())
+ ->method('mergePolicies')
+ ->with($defaultPolicy, $currentPolicy)
+ ->willReturn($mergedPolicy);
+ $response->expects($this->once())
+ ->method('setContentSecurityPolicy')
+ ->with($mergedPolicy);
+
+ $this->middleware->afterController($this->controller, 'test', $response);
+ }
+
+ public function testAfterControllerEmptyCSP() {
+ $response = $this->createMock(Response::class);
+ $emptyPolicy = new EmptyContentSecurityPolicy();
+ $response->expects($this->any())
+ ->method('getContentSecurityPolicy')
+ ->willReturn($emptyPolicy);
+ $response->expects($this->never())
+ ->method('setContentSecurityPolicy');
+
+ $this->middleware->afterController($this->controller, 'test', $response);
+ }
+
+ public function testAfterControllerWithContentSecurityPolicy3Support() {
+ $this->cspNonceManager
+ ->expects($this->once())
+ ->method('browserSupportsCspV3')
+ ->willReturn(true);
+ $token = $this->createMock(CsrfToken::class);
+ $token
+ ->expects($this->once())
+ ->method('getEncryptedValue')
+ ->willReturn('MyEncryptedToken');
+ $this->csrfTokenManager
+ ->expects($this->once())
+ ->method('getToken')
+ ->willReturn($token);
+ $response = $this->createMock(Response::class);
+ $defaultPolicy = new ContentSecurityPolicy();
+ $defaultPolicy->addAllowedImageDomain('defaultpolicy');
+ $currentPolicy = new ContentSecurityPolicy();
+ $currentPolicy->addAllowedConnectDomain('currentPolicy');
+ $mergedPolicy = new ContentSecurityPolicy();
+ $mergedPolicy->addAllowedMediaDomain('mergedPolicy');
+ $response
+ ->expects($this->exactly(2))
+ ->method('getContentSecurityPolicy')
+ ->willReturn($currentPolicy);
+ $this->contentSecurityPolicyManager
+ ->expects($this->once())
+ ->method('getDefaultPolicy')
+ ->willReturn($defaultPolicy);
+ $this->contentSecurityPolicyManager
+ ->expects($this->once())
+ ->method('mergePolicies')
+ ->with($defaultPolicy, $currentPolicy)
+ ->willReturn($mergedPolicy);
+ $response->expects($this->once())
+ ->method('setContentSecurityPolicy')
+ ->with($mergedPolicy);
+
+ $this->assertEquals($response, $this->middleware->afterController($this->controller, 'test', $response));
+ }
+}
diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
index ab243616be0..6a1adf03b2f 100644
--- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
@@ -72,12 +72,6 @@ class SecurityMiddlewareTest extends \Test\TestCase {
private $navigationManager;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $urlGenerator;
- /** @var ContentSecurityPolicyManager|\PHPUnit_Framework_MockObject_MockObject */
- private $contentSecurityPolicyManager;
- /** @var CsrfTokenManager|\PHPUnit_Framework_MockObject_MockObject */
- private $csrfTokenManager;
- /** @var ContentSecurityPolicyNonceManager|\PHPUnit_Framework_MockObject_MockObject */
- private $cspNonceManager;
/** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */
private $appManager;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
@@ -92,9 +86,6 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$this->navigationManager = $this->createMock(INavigationManager::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->request = $this->createMock(IRequest::class);
- $this->contentSecurityPolicyManager = $this->createMock(ContentSecurityPolicyManager::class);
- $this->csrfTokenManager = $this->createMock(CsrfTokenManager::class);
- $this->cspNonceManager = $this->createMock(ContentSecurityPolicyNonceManager::class);
$this->l10n = $this->createMock(IL10N::class);
$this->middleware = $this->getMiddleware(true, true, false);
$this->secException = new SecurityException('hey', false);
@@ -118,9 +109,6 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$isLoggedIn,
$isAdminUser,
$isSubAdmin,
- $this->contentSecurityPolicyManager,
- $this->csrfTokenManager,
- $this->cspNonceManager,
$this->appManager,
$this->l10n
);
@@ -611,91 +599,6 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$this->assertTrue($response instanceof JSONResponse);
}
- public function testAfterController() {
- $this->cspNonceManager
- ->expects($this->once())
- ->method('browserSupportsCspV3')
- ->willReturn(false);
- $response = $this->createMock(Response::class);
- $defaultPolicy = new ContentSecurityPolicy();
- $defaultPolicy->addAllowedImageDomain('defaultpolicy');
- $currentPolicy = new ContentSecurityPolicy();
- $currentPolicy->addAllowedConnectDomain('currentPolicy');
- $mergedPolicy = new ContentSecurityPolicy();
- $mergedPolicy->addAllowedMediaDomain('mergedPolicy');
- $response
- ->expects($this->exactly(2))
- ->method('getContentSecurityPolicy')
- ->willReturn($currentPolicy);
- $this->contentSecurityPolicyManager
- ->expects($this->once())
- ->method('getDefaultPolicy')
- ->willReturn($defaultPolicy);
- $this->contentSecurityPolicyManager
- ->expects($this->once())
- ->method('mergePolicies')
- ->with($defaultPolicy, $currentPolicy)
- ->willReturn($mergedPolicy);
- $response->expects($this->once())
- ->method('setContentSecurityPolicy')
- ->with($mergedPolicy);
-
- $this->middleware->afterController($this->controller, 'test', $response);
- }
-
- public function testAfterControllerEmptyCSP() {
- $response = $this->createMock(Response::class);
- $emptyPolicy = new EmptyContentSecurityPolicy();
- $response->expects($this->any())
- ->method('getContentSecurityPolicy')
- ->willReturn($emptyPolicy);
- $response->expects($this->never())
- ->method('setContentSecurityPolicy');
-
- $this->middleware->afterController($this->controller, 'test', $response);
- }
-
- public function testAfterControllerWithContentSecurityPolicy3Support() {
- $this->cspNonceManager
- ->expects($this->once())
- ->method('browserSupportsCspV3')
- ->willReturn(true);
- $token = $this->createMock(CsrfToken::class);
- $token
- ->expects($this->once())
- ->method('getEncryptedValue')
- ->willReturn('MyEncryptedToken');
- $this->csrfTokenManager
- ->expects($this->once())
- ->method('getToken')
- ->willReturn($token);
- $response = $this->createMock(Response::class);
- $defaultPolicy = new ContentSecurityPolicy();
- $defaultPolicy->addAllowedImageDomain('defaultpolicy');
- $currentPolicy = new ContentSecurityPolicy();
- $currentPolicy->addAllowedConnectDomain('currentPolicy');
- $mergedPolicy = new ContentSecurityPolicy();
- $mergedPolicy->addAllowedMediaDomain('mergedPolicy');
- $response
- ->expects($this->exactly(2))
- ->method('getContentSecurityPolicy')
- ->willReturn($currentPolicy);
- $this->contentSecurityPolicyManager
- ->expects($this->once())
- ->method('getDefaultPolicy')
- ->willReturn($defaultPolicy);
- $this->contentSecurityPolicyManager
- ->expects($this->once())
- ->method('mergePolicies')
- ->with($defaultPolicy, $currentPolicy)
- ->willReturn($mergedPolicy);
- $response->expects($this->once())
- ->method('setContentSecurityPolicy')
- ->with($mergedPolicy);
-
- $this->assertEquals($response, $this->middleware->afterController($this->controller, 'test', $response));
- }
-
public function dataRestrictedApp() {
return [
[false, false, false,],
diff --git a/tests/lib/Files/Cache/CacheTest.php b/tests/lib/Files/Cache/CacheTest.php
index f94b4f57078..eaea1692fe2 100644
--- a/tests/lib/Files/Cache/CacheTest.php
+++ b/tests/lib/Files/Cache/CacheTest.php
@@ -328,76 +328,6 @@ class CacheTest extends \Test\TestCase {
$this->assertEquals(2, count($this->cache->searchByMime('foo/file')));
}
- function testSearchByTag() {
- $userId = $this->getUniqueId('user');
- \OC::$server->getUserManager()->createUser($userId, $userId);
- $this->loginAsUser($userId);
- $user = new \OC\User\User($userId, null, \OC::$server->getEventDispatcher());
-
- $file1 = 'folder';
- $file2 = 'folder/foobar';
- $file3 = 'folder/foo';
- $file4 = 'folder/foo2';
- $file5 = 'folder/foo3';
- $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'foo/folder');
- $fileData = array();
- $fileData['foobar'] = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
- $fileData['foo'] = array('size' => 20, 'mtime' => 25, 'mimetype' => 'foo/file');
- $fileData['foo2'] = array('size' => 25, 'mtime' => 28, 'mimetype' => 'foo/file');
- $fileData['foo3'] = array('size' => 88, 'mtime' => 34, 'mimetype' => 'foo/file');
-
- $id1 = $this->cache->put($file1, $data1);
- $id2 = $this->cache->put($file2, $fileData['foobar']);
- $id3 = $this->cache->put($file3, $fileData['foo']);
- $id4 = $this->cache->put($file4, $fileData['foo2']);
- $id5 = $this->cache->put($file5, $fileData['foo3']);
-
- $tagManager = \OC::$server->getTagManager()->load('files', [], false, $userId);
- $this->assertTrue($tagManager->tagAs($id1, 'tag1'));
- $this->assertTrue($tagManager->tagAs($id1, 'tag2'));
- $this->assertTrue($tagManager->tagAs($id2, 'tag2'));
- $this->assertTrue($tagManager->tagAs($id3, 'tag1'));
- $this->assertTrue($tagManager->tagAs($id4, 'tag2'));
-
- // use tag name
- $results = $this->cache->searchByTag('tag1', $userId);
-
- $this->assertEquals(2, count($results));
-
- usort($results, function ($value1, $value2) {
- return $value1['name'] >= $value2['name'];
- });
-
- $this->assertEquals('folder', $results[0]['name']);
- $this->assertEquals('foo', $results[1]['name']);
-
- // use tag id
- $tags = $tagManager->getTagsForUser($userId);
- $this->assertNotEmpty($tags);
- $tags = array_filter($tags, function ($tag) {
- return $tag->getName() === 'tag2';
- });
- $results = $this->cache->searchByTag(current($tags)->getId(), $userId);
- $this->assertEquals(3, count($results));
-
- usort($results, function ($value1, $value2) {
- return $value1['name'] >= $value2['name'];
- });
-
- $this->assertEquals('folder', $results[0]['name']);
- $this->assertEquals('foo2', $results[1]['name']);
- $this->assertEquals('foobar', $results[2]['name']);
-
- $tagManager->delete('tag1');
- $tagManager->delete('tag2');
-
- $this->logout();
- $user = \OC::$server->getUserManager()->get($userId);
- if ($user !== null) {
- $user->delete();
- }
- }
-
function testSearchQueryByTag() {
$userId = static::getUniqueID('user');
\OC::$server->getUserManager()->createUser($userId, $userId);
diff --git a/tests/lib/Files/Node/FolderTest.php b/tests/lib/Files/Node/FolderTest.php
index 061b9419f39..3390d19feb7 100644
--- a/tests/lib/Files/Node/FolderTest.php
+++ b/tests/lib/Files/Node/FolderTest.php
@@ -432,57 +432,6 @@ class FolderTest extends NodeTest {
$this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
}
- public function testSearchByTag() {
- $manager = $this->createMock(Manager::class);
- /**
- * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
- */
- $view = $this->createMock(View::class);
- $root = $this->getMockBuilder(Root::class)
- ->setConstructorArgs([$manager, $view, $this->user, $this->userMountCache, $this->logger, $this->userManager])
- ->getMock();
- $root->expects($this->any())
- ->method('getUser')
- ->will($this->returnValue($this->user));
- $storage = $this->createMock(Storage::class);
- $storage->method('getId')->willReturn('');
- $cache = $this->getMockBuilder(Cache::class)->setConstructorArgs([$storage])->getMock();
-
- $mount = $this->createMock(IMountPoint::class);
- $mount->expects($this->once())
- ->method('getStorage')
- ->will($this->returnValue($storage));
- $mount->expects($this->once())
- ->method('getInternalPath')
- ->will($this->returnValue('foo'));
-
- $storage->expects($this->once())
- ->method('getCache')
- ->will($this->returnValue($cache));
-
- $cache->expects($this->once())
- ->method('searchByTag')
- ->with('tag1', 'user1')
- ->will($this->returnValue(array(
- array('fileid' => 3, 'path' => 'foo/qwerty', 'name' => 'qwerty', 'size' => 200, 'mtime' => 55, 'mimetype' => 'text/plain')
- )));
-
- $root->expects($this->once())
- ->method('getMountsIn')
- ->with('/bar/foo')
- ->will($this->returnValue(array()));
-
- $root->expects($this->once())
- ->method('getMount')
- ->with('/bar/foo')
- ->will($this->returnValue($mount));
-
- $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo');
- $result = $node->searchByTag('tag1', 'user1');
- $this->assertEquals(1, count($result));
- $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath());
- }
-
public function testSearchSubStorages() {
$manager = $this->createMock(Manager::class);
/**
diff --git a/tests/lib/Lockdown/Filesystem/NullCacheTest.php b/tests/lib/Lockdown/Filesystem/NullCacheTest.php
index 3a4e3f3a402..7773241fca1 100644
--- a/tests/lib/Lockdown/Filesystem/NullCacheTest.php
+++ b/tests/lib/Lockdown/Filesystem/NullCacheTest.php
@@ -139,10 +139,6 @@ class NulLCacheTest extends \Test\TestCase {
$this->assertSame([], $this->cache->searchByMime('foo'));
}
- public function testSearchByTag() {
- $this->assertSame([], $this->cache->searchByTag('foo', 'user'));
- }
-
public function testGetIncomplete() {
$this->assertSame([], $this->cache->getIncomplete());
}