Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/Segment/Consumer/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
25 changes: 25 additions & 0 deletions test/ConsumerFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down