diff --git a/lib/Segment/Consumer/File.php b/lib/Segment/Consumer/File.php index d59d71c..a0d385e 100644 --- a/lib/Segment/Consumer/File.php +++ b/lib/Segment/Consumer/File.php @@ -20,7 +20,11 @@ public function __construct($secret, $options = array()) { try { $this->file_handle = fopen($options["filename"], "a"); - chmod($options["filename"], 0777); + if (isset($options["filepermissions"])) { + chmod($options["filename"], $options["filepermissions"]); + } else { + chmod($options["filename"], 0777); + } } catch (Exception $e) { $this->handleError($e->getCode(), $e->getMessage()); } diff --git a/test/ConsumerFileTest.php b/test/ConsumerFileTest.php index 510ffaf..82ab848 100644 --- a/test/ConsumerFileTest.php +++ b/test/ConsumerFileTest.php @@ -123,6 +123,31 @@ public function testProductionProblems() $this->assertFalse($tracked); } + public function testFileSecurityCustom() { + $client = new Segment_Client( + "testsecret", + array( + "consumer" => "file", + "filename" => $this->filename, + "filepermissions" => 0700 + ) + ); + $tracked = $client->track(array("userId" => "some_user", "event" => "File PHP Event")); + $this->assertEquals(0700, (fileperms($this->filename) & 0777)); + } + + public function testFileSecurityDefaults() { + $client = new Segment_Client( + "testsecret", + array( + "consumer" => "file", + "filename" => $this->filename + ) + ); + $tracked = $client->track(array("userId" => "some_user", "event" => "File PHP Event")); + $this->assertEquals(0777, (fileperms($this->filename) & 0777)); + } + public function checkWritten($type) { exec("wc -l " . $this->filename, $output);