-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Move public webdav auth to share manager #23736
Merged
DeepDiver1975
merged 3 commits into
master
from
move_public_webdav_auth_to_share_manager
Apr 8, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
<?php | ||
|
||
namespace OCA\DAV\Tests\Unit\Connector; | ||
|
||
use OCP\IRequest; | ||
use OCP\ISession; | ||
use OCP\Share\Exceptions\ShareNotFound; | ||
use OCP\Share\IManager; | ||
|
||
class PublicAuth extends \Test\TestCase { | ||
|
||
/** @var ISession|\PHPUnit_Framework_MockObject_MockObject */ | ||
private $session; | ||
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */ | ||
private $request; | ||
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ | ||
private $shareManager; | ||
/** @var \OCA\DAV\Connector\PublicAuth */ | ||
private $auth; | ||
|
||
/** @var string */ | ||
private $oldUser; | ||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
|
||
$this->session = $this->getMock('\OCP\ISession'); | ||
$this->request = $this->getMock('\OCP\IRequest'); | ||
$this->shareManager = $this->getMock('\OCP\Share\IManager'); | ||
|
||
$this->auth = new \OCA\DAV\Connector\PublicAuth( | ||
$this->request, | ||
$this->shareManager, | ||
$this->session | ||
); | ||
|
||
// Store current user | ||
$this->oldUser = \OC_User::getUser(); | ||
} | ||
|
||
protected function tearDown() { | ||
\OC_User::setIncognitoMode(false); | ||
|
||
// Set old user | ||
\OC_User::setUserId($this->oldUser); | ||
\OC_Util::setupFS($this->oldUser); | ||
|
||
parent::tearDown(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing parent::tearDown There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
|
||
public function testNoShare() { | ||
$this->shareManager->expects($this->once()) | ||
->method('getShareByToken') | ||
->willThrowException(new ShareNotFound()); | ||
|
||
$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); | ||
|
||
$this->assertFalse($result); | ||
} | ||
|
||
public function testShareNoPassword() { | ||
$share = $this->getMock('OCP\Share\IShare'); | ||
$share->method('getPassword')->willReturn(null); | ||
|
||
$this->shareManager->expects($this->once()) | ||
->method('getShareByToken') | ||
->willReturn($share); | ||
|
||
$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); | ||
|
||
$this->assertTrue($result); | ||
} | ||
|
||
public function testSharePasswordFancyShareType() { | ||
$share = $this->getMock('OCP\Share\IShare'); | ||
$share->method('getPassword')->willReturn('password'); | ||
$share->method('getShareType')->willReturn(42); | ||
|
||
$this->shareManager->expects($this->once()) | ||
->method('getShareByToken') | ||
->willReturn($share); | ||
|
||
$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); | ||
|
||
$this->assertFalse($result); | ||
} | ||
|
||
|
||
public function testSharePasswordRemote() { | ||
$share = $this->getMock('OCP\Share\IShare'); | ||
$share->method('getPassword')->willReturn('password'); | ||
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_REMOTE); | ||
|
||
$this->shareManager->expects($this->once()) | ||
->method('getShareByToken') | ||
->willReturn($share); | ||
|
||
$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); | ||
|
||
$this->assertTrue($result); | ||
} | ||
|
||
public function testSharePasswordLinkValidPassword() { | ||
$share = $this->getMock('OCP\Share\IShare'); | ||
$share->method('getPassword')->willReturn('password'); | ||
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); | ||
|
||
$this->shareManager->expects($this->once()) | ||
->method('getShareByToken') | ||
->willReturn($share); | ||
|
||
$this->shareManager->expects($this->once()) | ||
->method('checkPassword')->with( | ||
$this->equalTo($share), | ||
$this->equalTo('password') | ||
)->willReturn(true); | ||
|
||
$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); | ||
|
||
$this->assertTrue($result); | ||
} | ||
|
||
public function testSharePasswordLinkValidSession() { | ||
$share = $this->getMock('OCP\Share\IShare'); | ||
$share->method('getPassword')->willReturn('password'); | ||
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); | ||
$share->method('getId')->willReturn('42'); | ||
|
||
$this->shareManager->expects($this->once()) | ||
->method('getShareByToken') | ||
->willReturn($share); | ||
|
||
$this->shareManager->method('checkPassword') | ||
->with( | ||
$this->equalTo($share), | ||
$this->equalTo('password') | ||
)->willReturn(false); | ||
|
||
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true); | ||
$this->session->method('get')->with('public_link_authenticated')->willReturn('42'); | ||
|
||
$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); | ||
|
||
$this->assertTrue($result); | ||
} | ||
|
||
public function testSharePasswordLinkInvalidSession() { | ||
$share = $this->getMock('OCP\Share\IShare'); | ||
$share->method('getPassword')->willReturn('password'); | ||
$share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); | ||
$share->method('getId')->willReturn('42'); | ||
|
||
$this->shareManager->expects($this->once()) | ||
->method('getShareByToken') | ||
->willReturn($share); | ||
|
||
$this->shareManager->method('checkPassword') | ||
->with( | ||
$this->equalTo($share), | ||
$this->equalTo('password') | ||
)->willReturn(false); | ||
|
||
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true); | ||
$this->session->method('get')->with('public_link_authenticated')->willReturn('43'); | ||
|
||
$result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']); | ||
|
||
$this->assertFalse($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing parent::setUp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed