Skip to content
Closed
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/Analytics/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
23 changes: 21 additions & 2 deletions test/ConsumerFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,30 @@ function testProductionProblems() {
$this->assertFalse($tracked);
}

function testFileSecurity() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename this to testFileSecurityCustom?

$client = new Analytics_Client("testsecret",
array("consumer" => "file",
"filename" => $this->filename,
"filepermissions" => 0700 ));

$tracked = $client->track("some_user", "File PHP Event");
$this->assertEquals(0700, (fileperms($this->filename) & 0777));
}

function testFileSecurityDefaults() {
$client = new Analytics_Client("testsecret",
array("consumer" => "file",
"filename" => $this->filename ));

$tracked = $client->track("some_user", "File PHP Event");
$this->assertEquals(0777, (fileperms($this->filename) & 0777));
}

function checkWritten() {
exec("wc -l " . $this->filename, $output);
$this->assertEquals($output[0], "1 " . $this->filename);
$this->assertEquals(trim($output[0]), "1 " . $this->filename);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some trouble making the tests pass without trimming this first. I believe this should affect anything else, and might actually make the test suite slightly more portable. But let me know if you don't like it and I can remove it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok to me. What was the failure without this?

unlink($this->filename);
}

}
?>
?>