From 272492da6ba540e3768355c33626f9150359ff62 Mon Sep 17 00:00:00 2001 From: et-nik Date: Thu, 8 Nov 2018 20:27:11 +0300 Subject: [PATCH 1/2] Add getVisibility test for private permission --- tests/SftpAdapterTests.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/SftpAdapterTests.php b/tests/SftpAdapterTests.php index c897d93..63ce784 100644 --- a/tests/SftpAdapterTests.php +++ b/tests/SftpAdapterTests.php @@ -272,6 +272,24 @@ public function testGetVisibility($filesystem, $adapter, $mock) $this->assertEquals('public', $result); } + /** + * @dataProvider adapterProvider + */ + public function testGetVisibilityPrivate($filesystem, $adapter, $mock) + { + $mock->shouldReceive('stat')->andReturn([ + 'type' => NET_SFTP_TYPE_DIRECTORY, + 'mtime' => time(), + 'size' => 20, + 'permissions' => 0700, + ]); + $result = $adapter->getVisibility(uniqid().'object.ext'); + $this->assertInternalType('array', $result); + $result = $result['visibility']; + $this->assertInternalType('string', $result); + $this->assertEquals('private', $result); + } + /** * @dataProvider adapterProvider */ From ef37a276a8d41972f173e1d1ee4624224deb264a Mon Sep 17 00:00:00 2001 From: et-nik Date: Thu, 8 Nov 2018 20:30:56 +0300 Subject: [PATCH 2/2] Fix visibility checking --- src/SftpAdapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SftpAdapter.php b/src/SftpAdapter.php index 2eb1afb..04f81e0 100644 --- a/src/SftpAdapter.php +++ b/src/SftpAdapter.php @@ -503,7 +503,7 @@ public function getMetadata($path) $result = Util::map($info, $this->statMap); $result['type'] = $info['type'] === NET_SFTP_TYPE_DIRECTORY ? 'dir' : 'file'; - $result['visibility'] = $info['permissions'] & $this->permPublic ? 'public' : 'private'; + $result['visibility'] = $info['permissions'] & (0777 ^ $this->permPrivate) ? 'public' : 'private'; return $result; }