Browse Source

don't compare host on relative URLs

also adds test for ensuring other webmentions aren't sent when using target_domain
pull/9/head
Aaron Parecki 8 years ago
parent
commit
1a20005c71
2 changed files with 25 additions and 3 deletions
  1. +1
    -1
      controllers/API.php
  2. +24
    -2
      tests/APITest.php

+ 1
- 1
controllers/API.php View File

@ -105,7 +105,7 @@ class API {
$domain = parse_url($url, PHP_URL_HOST);
if($url == $target || $domain == $target_domain ||
# subdomain check
($target_domain and substr_compare($domain, '.' . $target_domain, -(strlen($target_domain) + 1)) == 0)) {
($target_domain and $domain and substr_compare($domain, '.' . $target_domain, -(strlen($target_domain) + 1)) == 0)) {
$found[$url] = null;
}
}

+ 24
- 2
tests/APITest.php View File

@ -52,9 +52,8 @@ class APITest extends PHPUnit_Framework_TestCase {
# Verify it queued the mention in the database
$d = ORM::for_table('webmentions')->where(['source' => $source, 'target' => $target])->find_one();
$this->assertNotNull($d);
$this->assertNotFalse($d);
$this->assertEquals($match[1], $d->token);
# Check the status endpoint to make sure it says it's still queued
$response = $this->status($d->token);
$this->assertEquals(200, $response->getStatusCode());
@ -62,6 +61,12 @@ class APITest extends PHPUnit_Framework_TestCase {
$this->assertEquals('queued', $data->status);
}
private function _assertNotQueued($source, $target) {
# Verify it did not queue a mention in the database
$d = ORM::for_table('webmentions')->where(['source' => $source, 'target' => $target])->find_one();
$this->assertFalse($d);
}
public function testAuthentication() {
$response = $this->webmention([]);
$this->assertEquals(401, $response->getStatusCode());
@ -192,6 +197,23 @@ class APITest extends PHPUnit_Framework_TestCase {
$this->_assertQueued('http://source.example.com/basictest', 'http://target2.example.com', $data->location[1]);
}
public function testTargetDomainQueuesOnlyWebmentionsFromTargetDomain() {
$this->_createExampleAccount();
$response = $this->webmention(['token'=>'a','source'=>'http://source.example.com/multipletest','target_domain'=>'example.com']);
$body = $response->getContent();
$this->assertEquals(201, $response->getStatusCode(), $body);
$data = json_decode($body);
$this->assertEquals(false, property_exists($data, 'error'), $body);
$this->assertEquals('queued', $data->status, $body);
$this->assertEquals(2, count($data->location), $body);
$this->_assertQueued('http://source.example.com/multipletest', 'http://target.example.com', $data->location[0]);
$this->_assertQueued('http://source.example.com/multipletest', 'http://target2.example.com', $data->location[1]);
$this->_assertNotQueued('http://source.example.com/multipletest', 'http://target.example.org');
$this->_assertNotQueued('http://source.example.com/multipletest', '/relativelink');
$this->_assertNotQueued('http://source.example.com/multipletest', 'http://source.example.com/relativelink');
}
public function testStatusNotFound() {
$this->_createExampleAccount();

Loading…
Cancel
Save