Skip to content

Commit

Permalink
Hide information about walls the user doesn't have access to
Browse files Browse the repository at this point in the history
  • Loading branch information
birtles committed Mar 26, 2013
1 parent dcb6dd0 commit 346102a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
4 changes: 2 additions & 2 deletions wall/lib/walls.inc
Expand Up @@ -372,13 +372,13 @@ class Wall {
return $config['editor']['url'] . $path;
}

protected function canAdminister() {
public function canAdminister() {
// In the future we will check if the wall has been shared with the current
// user or not
return $this->isOwner();
}

protected function isOwner() {
public function isOwner() {
if (!isset($this->email) || $this->ownerEmail === null)
return false;
return $this->email == $this->ownerEmail;
Expand Down
14 changes: 14 additions & 0 deletions wall/public/api/doWalls.php
Expand Up @@ -51,6 +51,20 @@
if ($wall === null)
bailWithError('not-found');

// Walls::getById will filter out sensitive information if the supplied
// email address does not have access to administer the wall.
//
// However, for now we disallow all access if the user doesn't have
// administration rights since a user may want to keep their event private
// from others for various reasons.
//
// In the future we will probably fine tune this so that walls which are
// marked for display in the public gallery can be reached from this API
// since we won't be exposing any information via this API that isn't
// available by browsing the gallery.
if (!$wall->canAdminister())
bailWithError('no-auth');

$result = $wall->asArray();
break;

Expand Down
3 changes: 1 addition & 2 deletions wall/tests/api/TestCreateWall.php
Expand Up @@ -112,8 +112,7 @@ function testEmail() {

// Try a bad email
$this->logout();
$this->userEmail = 'abc';
$this->login();
$this->login('abc');
$wall = $this->createWall('Test wall', $this->testDesignId);
$this->assertEqual(@$wall['error_key'], 'bad-email');
}
Expand Down
17 changes: 16 additions & 1 deletion wall/tests/api/TestGetWall.php
Expand Up @@ -80,7 +80,22 @@ function testNotFound() {
$this->assertEqual(@$wall['error_key'], 'not-found');
}

// XXX Check we can't get the information of someone else's wall
function testSomeoneElsesWall() {
// Create wall
$this->login();
$wall = $this->createWall('Test wall', $this->testDesignId);
$wallId = $wall['wallId'];
$this->logout();

// Login as someone else
$this->login('abc@abc.org');
$wall = $this->getWall($wallId);
$this->assertEqual(@$wall['error_key'], 'no-auth');
$this->logout();

// Tidy up
$this->removeWall($wallId);
}

function looksLikeAUrl($url) {
$parts = parse_url($url);
Expand Down
15 changes: 9 additions & 6 deletions wall/tests/api/WallMakerTestCase.php
Expand Up @@ -24,6 +24,8 @@
*/
abstract class WallMakerTestCase extends WallTestCase {

const DEFAULT_USER_EMAIL = 'test@test.org';

static private $updatedSessionSettings = false;

protected $sessionId = null;
Expand All @@ -41,27 +43,27 @@ function __construct($name = false) {

function setUp() {
$this->sessionId = null;

$this->userEmail = "test@test.org";
$this->userEmail = null;
$this->createTestDesign(array('test.jpg'));
}

function tearDown() {
if ($this->sessionId) {
$this->logout();
}

$this->userEmail = null;
$this->removeTestDesign();
}

function login() {
function login($email = null) {
session_name(WALLMAKER_SESSION_NAME);
session_cache_limiter(''); // Prevent warnings about not being able to send
// cache limiting headers
session_start();

$_SESSION['email'] = $this->userEmail;
$email = $email ? $email : self::DEFAULT_USER_EMAIL;

$_SESSION['email'] = $email;
$this->userEmail = $email;

// We're about to call into the wall server which will want to access the
// same session but session files are opened exclusively so we store the
Expand All @@ -83,6 +85,7 @@ function logout() {

// Clear local state
$this->sessionId = null;
$this->userEmail = null;

// When you create cookies without an expiry date they are treated as
// temporary cookies.
Expand Down

0 comments on commit 346102a

Please sign in to comment.