public function testGetGrantsApi() { $value = $this->faker->word; $secret = $this->faker->sha1; $target = new EffectiveRightsTargetSelector(TargetType::ACCOUNT(), TargetBy::NAME(), $value); $grantee = new GranteeSelector($value, GranteeType::USR(), GranteeBy::ID(), $secret, true); $this->api->getGrants($target, $grantee); $client = $this->api->getClient(); $req = $client->lastRequest(); $xml = '<?xml version="1.0"?>' . "\n" . '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:zimbra" xmlns:urn1="urn:zimbraAdmin">' . '<env:Body>' . '<urn1:GetGrantsRequest>' . '<urn1:target type="' . TargetType::ACCOUNT() . '" by="' . TargetBy::NAME() . '">' . $value . '</urn1:target>' . '<urn1:grantee type="' . GranteeType::USR() . '" by="' . GranteeBy::ID() . '" secret="' . $secret . '" all="true">' . $value . '</urn1:grantee>' . '</urn1:GetGrantsRequest>' . '</env:Body>' . '</env:Envelope>'; $this->assertXmlStringEqualsXmlString($xml, (string) $req); }
public function testCheckRightsApi() { $key = $this->faker->word; $right1 = $this->faker->word; $right2 = $this->faker->word; $target = new CheckRightsTargetSpec(TargetType::DOMAIN(), TargetBy::ID(), $key, [$right1, $right2]); $this->api->checkRights([$target]); $client = $this->api->getClient(); $req = $client->lastRequest(); $xml = '<?xml version="1.0"?>' . "\n" . '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:zimbra" xmlns:urn1="urn:zimbraAccount">' . '<env:Body>' . '<urn1:CheckRightsRequest>' . '<urn1:target type="' . TargetType::DOMAIN() . '" by="' . TargetBy::ID() . '" key="' . $key . '">' . '<urn1:right>' . $right1 . '</urn1:right>' . '<urn1:right>' . $right2 . '</urn1:right>' . '</urn1:target>' . '</urn1:CheckRightsRequest>' . '</env:Body>' . '</env:Envelope>'; $this->assertXmlStringEqualsXmlString($xml, (string) $req); }
public function testRevokeRightApi() { $value = $this->faker->word; $secret = $this->faker->word; $target = new EffectiveRightsTargetSelector(TargetType::ACCOUNT(), TargetBy::NAME(), $value); $grantee = new GranteeSelector($value, GranteeType::USR(), GranteeBy::ID(), $secret, true); $right = new RightModifierInfo($value, true, false, false, true); $this->api->revokeRight($target, $grantee, $right); $client = $this->api->getClient(); $req = $client->lastRequest(); $xml = '<?xml version="1.0"?>' . "\n" . '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:zimbra" xmlns:urn1="urn:zimbraAdmin">' . '<env:Body>' . '<urn1:RevokeRightRequest>' . '<urn1:target type="' . TargetType::ACCOUNT() . '" by="' . TargetBy::NAME() . '">' . $value . '</urn1:target>' . '<urn1:grantee type="' . GranteeType::USR() . '" by="' . GranteeBy::ID() . '" secret="' . $secret . '" all="true">' . $value . '</urn1:grantee>' . '<urn1:right deny="true" canDelegate="false" disinheritSubGroups="false" subDomain="true">' . $value . '</urn1:right>' . '</urn1:RevokeRightRequest>' . '</env:Body>' . '</env:Envelope>'; $this->assertXmlStringEqualsXmlString($xml, (string) $req); }
public function testEffectiveRightsTargetSelector() { $value = $this->faker->word; $target = new EffectiveRightsTargetSelector(TargetType::DOMAIN(), TargetBy::ID(), $value); $this->assertTrue($target->getType()->is('domain')); $this->assertSame($value, $target->getValue()); $this->assertSame('id', $target->getBy()->value()); $target->setType(TargetType::ACCOUNT())->setBy(TargetBy::NAME()); $this->assertSame('account', $target->getType()->value()); $this->assertSame('name', $target->getBy()->value()); $xml = '<?xml version="1.0"?>' . "\n" . '<target type="' . TargetType::ACCOUNT() . '" by="' . TargetBy::NAME() . '">' . $value . '</target>'; $this->assertXmlStringEqualsXmlString($xml, (string) $target); $array = ['target' => ['type' => TargetType::ACCOUNT()->value(), '_content' => $value, 'by' => TargetBy::NAME()->value()]]; $this->assertEquals($array, $target->toArray()); }
public function testCheckRightsTargetSpec() { $key = $this->faker->word; $right1 = $this->faker->word; $right2 = $this->faker->word; $right3 = $this->faker->word; $target = new CheckRightsTargetSpec(TargetType::DOMAIN(), TargetBy::ID(), $key, [$right1, $right2]); $this->assertTrue($target->getTargetType()->is('domain')); $this->assertTrue($target->getTargetBy()->is('id')); $this->assertSame($key, $target->getTargetKey()); $this->assertSame([$right1, $right2], $target->getRights()->all()); $target->setTargetType(TargetType::ACCOUNT())->setTargetBy(TargetBy::NAME())->setTargetKey($key)->addRight($right3); $this->assertTrue($target->getTargetType()->is('account')); $this->assertTrue($target->getTargetBy()->is('name')); $this->assertSame($key, $target->getTargetKey()); $this->assertSame([$right1, $right2, $right3], $target->getRights()->all()); $xml = '<?xml version="1.0"?>' . "\n" . '<target type="' . TargetType::ACCOUNT() . '" by="' . TargetBy::NAME() . '" key="' . $key . '">' . '<right>' . $right1 . '</right>' . '<right>' . $right2 . '</right>' . '<right>' . $right3 . '</right>' . '</target>'; $this->assertXmlStringEqualsXmlString($xml, (string) $target); $array = ['target' => ['type' => TargetType::ACCOUNT()->value(), 'by' => TargetBy::NAME()->value(), 'key' => $key, 'right' => [$right1, $right2, $right3]]]; $this->assertEquals($array, $target->toArray()); }
public function testTargetBy() { $values = array('id', 'name'); foreach ($values as $value) { $this->assertTrue(\Zimbra\Enum\TargetBy::has($value)); } }
public function testCheckRights() { $key = self::randomName(); $right1 = md5(self::randomString()); $right2 = md5(self::randomString()); $target = new \Zimbra\Account\Struct\CheckRightsTargetSpec(TargetType::DOMAIN(), TargetBy::ID(), $key, array($right1, $right2)); $this->_api->checkRights(array($target)); $client = $this->_api->client(); $req = $client->lastRequest(); $xml = '<?xml version="1.0"?>' . "\n" . '<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:urn="urn:zimbra" xmlns:urn1="urn:zimbraAccount">' . '<env:Body>' . '<urn1:CheckRightsRequest>' . '<urn1:target type="' . TargetType::DOMAIN() . '" by="' . TargetBy::ID() . '" key="' . $key . '">' . '<urn1:right>' . $right1 . '</urn1:right>' . '<urn1:right>' . $right2 . '</urn1:right>' . '</urn1:target>' . '</urn1:CheckRightsRequest>' . '</env:Body>' . '</env:Envelope>'; $this->assertXmlStringEqualsXmlString($xml, (string) $req); }
public function testCheckRights() { $key = self::randomName(); $right1 = self::randomName(); $right2 = self::randomName(); $target = new \Zimbra\Account\Struct\CheckRightsTargetSpec(TargetType::DOMAIN(), TargetBy::ID(), $key, [$right1, $right2]); $req = new \Zimbra\Account\Request\CheckRights([$target]); $this->assertInstanceOf('Zimbra\\Account\\Request\\Base', $req); $this->assertSame([$target], $req->getTargets()->all()); $req->addTarget($target); $this->assertSame([$target, $target], $req->getTargets()->all()); $req->getTargets()->remove(1); $xml = '<?xml version="1.0"?>' . "\n" . '<CheckRightsRequest>' . '<target type="' . TargetType::DOMAIN() . '" by="' . TargetBy::ID() . '" key="' . $key . '">' . '<right>' . $right1 . '</right>' . '<right>' . $right2 . '</right>' . '</target>' . '</CheckRightsRequest>'; $this->assertXmlStringEqualsXmlString($xml, (string) $req); $array = ['CheckRightsRequest' => ['_jsns' => 'urn:zimbraAccount', 'target' => [['type' => TargetType::DOMAIN()->value(), 'by' => TargetBy::ID()->value(), 'key' => $key, 'right' => [$right1, $right2]]]]]; $this->assertEquals($array, $req->toArray()); }
public function testRevokeRight() { $value = self::randomName(); $secret = self::randomName(); $target = new \Zimbra\Admin\Struct\EffectiveRightsTargetSelector(TargetType::ACCOUNT(), TargetBy::NAME(), $value); $grantee = new \Zimbra\Admin\Struct\GranteeSelector($value, GranteeType::USR(), GranteeBy::ID(), $secret, true); $right = new \Zimbra\Admin\Struct\RightModifierInfo($value, true, false, false, true); $req = new \Zimbra\Admin\Request\RevokeRight($target, $grantee, $right); $this->assertInstanceOf('Zimbra\\Admin\\Request\\Base', $req); $this->assertSame($target, $req->getTarget()); $this->assertSame($grantee, $req->getGrantee()); $this->assertSame($right, $req->getRight()); $req->setTarget($target)->setGrantee($grantee)->setRight($right); $this->assertSame($target, $req->getTarget()); $this->assertSame($grantee, $req->getGrantee()); $this->assertSame($right, $req->getRight()); $xml = '<?xml version="1.0"?>' . "\n" . '<RevokeRightRequest>' . '<target type="' . TargetType::ACCOUNT() . '" by="' . TargetBy::NAME() . '">' . $value . '</target>' . '<grantee type="' . GranteeType::USR() . '" by="' . GranteeBy::ID() . '" secret="' . $secret . '" all="true">' . $value . '</grantee>' . '<right deny="true" canDelegate="false" disinheritSubGroups="false" subDomain="true">' . $value . '</right>' . '</RevokeRightRequest>'; $this->assertXmlStringEqualsXmlString($xml, (string) $req); $array = ['RevokeRightRequest' => ['_jsns' => 'urn:zimbraAdmin', 'target' => ['type' => TargetType::ACCOUNT()->value(), '_content' => $value, 'by' => TargetBy::NAME()->value()], 'grantee' => ['_content' => $value, 'type' => GranteeType::USR()->value(), 'by' => GranteeBy::ID()->value(), 'secret' => $secret, 'all' => true], 'right' => ['deny' => true, 'canDelegate' => false, 'disinheritSubGroups' => false, 'subDomain' => true, '_content' => $value]]]; $this->assertEquals($array, $req->toArray()); }