Zend_Service_Amazon_Ec2_Securitygroups = new Zend_Service_Amazon_Ec2_Securitygroups('access_key', 'secret_access_key');
$adapter = new Zend_Http_Client_Adapter_Test();
$client = new Zend_Http_Client(null, array(
'adapter' => $adapter
));
$this->adapter = $adapter;
Zend_Service_Amazon_Ec2_Securitygroups::setHttpClient($client);
}
/**
* Cleans up the environment after running a test.
*/
protected function tearDown()
{
unset($this->adapter);
$this->Zend_Service_Amazon_Ec2_Securitygroups = null;
parent::tearDown();
}
/**
* Tests Zend_Service_Amazon_Ec2_Securitygroups->authorize()
*/
public function testAuthorizeSinglePort()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. "\r\n"
. " true\r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->authorizeIp('MyGroup', 'tcp', '80', '80', '0.0.0.0/0');
$this->assertTrue($return);
}
public function testAuthorizeRangeOfPorts()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. "\r\n"
. " true\r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->authorizeIp('MyGroup', 'tcp', '6000', '7000', '0.0.0.0/0');
$this->assertTrue($return);
}
public function testAuthorizeSecurityGroupName()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. "\r\n"
. " true\r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->authorizeGroup('MyGroup', 'groupname', '15333848');
$this->assertTrue($return);
}
/**
* Tests Zend_Service_Amazon_Ec2_Securitygroups->create()
*/
public function testCreate()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. "\r\n"
. " true\r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->create('MyGroup', 'My Security Grup');
$this->assertTrue($return);
}
/**
* Tests Zend_Service_Amazon_Ec2_Securitygroups->delete()
*/
public function testDelete()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. "\r\n"
. " true\r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->delete('MyGroup');
$this->assertTrue($return);
}
/**
* Tests Zend_Service_Amazon_Ec2_Securitygroups->describe()
*/
public function testDescribeMultipleSecruityGroups()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. " \r\n"
. " - \r\n"
. " UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM\r\n"
. " WebServers\r\n"
. " Web\r\n"
. " \r\n"
. "
- \r\n"
. " tcp\r\n"
. " 80\r\n"
. " 80\r\n"
. " \r\n"
. " \r\n"
. "
- \r\n"
. " 0.0.0.0/0\r\n"
. "
\r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. " - \r\n"
. " UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM\r\n"
. " RangedPortsBySource\r\n"
. " A\r\n"
. " \r\n"
. "
- \r\n"
. " tcp\r\n"
. " 6000\r\n"
. " 7000\r\n"
. " \r\n"
. " \r\n"
. "
- \r\n"
. " 0.0.0.0/0\r\n"
. "
\r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->describe(array('WebServers','RangedPortsBySource'));
$this->assertEquals(2, count($return));
$arrGroups = array(
array(
'ownerId' => 'UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM',
'groupName' => 'WebServers',
'groupDescription' => 'Web',
'ipPermissions' => array(0 => array(
'ipProtocol' => 'tcp',
'fromPort' => '80',
'toPort' => '80',
'ipRanges' => '0.0.0.0/0'
))
),
array(
'ownerId' => 'UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM',
'groupName' => 'RangedPortsBySource',
'groupDescription' => 'A',
'ipPermissions' => array(0 => array(
'ipProtocol' => 'tcp',
'fromPort' => '6000',
'toPort' => '7000',
'ipRanges' => '0.0.0.0/0'
))
)
);
foreach($return as $k => $r) {
$this->assertSame($arrGroups[$k], $r);
}
}
public function testDescribeSingleSecruityGroup()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. " \r\n"
. " - \r\n"
. " UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM\r\n"
. " WebServers\r\n"
. " Web\r\n"
. " \r\n"
. "
- \r\n"
. " tcp\r\n"
. " 80\r\n"
. " 80\r\n"
. " \r\n"
. " \r\n"
. "
- \r\n"
. " 0.0.0.0/0\r\n"
. "
\r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->describe('WebServers');
$this->assertEquals(1, count($return));
$arrGroups = array(
array(
'ownerId' => 'UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM',
'groupName' => 'WebServers',
'groupDescription' => 'Web',
'ipPermissions' => array(0 => array(
'ipProtocol' => 'tcp',
'fromPort' => '80',
'toPort' => '80',
'ipRanges' => '0.0.0.0/0'
))
)
);
foreach($return as $k => $r) {
$this->assertSame($arrGroups[$k], $r);
}
}
public function testDescribeSingleSecruityGroupWithMultipleIpsSamePort()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. " \r\n"
. " - \r\n"
. " UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM\r\n"
. " WebServers\r\n"
. " Web\r\n"
. " \r\n"
. "
- \r\n"
. " tcp\r\n"
. " 80\r\n"
. " 80\r\n"
. " \r\n"
. " \r\n"
. "
- \r\n"
. " 0.0.0.0/0\r\n"
. "
\r\n"
. " - \r\n"
. " 1.1.1.1/0\r\n"
. "
\r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. " \r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->describe('WebServers');
$this->assertEquals(1, count($return));
$arrGroups = array(
array(
'ownerId' => 'UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM',
'groupName' => 'WebServers',
'groupDescription' => 'Web',
'ipPermissions' => array(0 => array(
'ipProtocol' => 'tcp',
'fromPort' => '80',
'toPort' => '80',
'ipRanges' => array(
'0.0.0.0/0',
'1.1.1.1/0'
)
))
)
);
foreach($return as $k => $r) {
$this->assertSame($arrGroups[$k], $r);
}
}
/**
* Tests Zend_Service_Amazon_Ec2_Securitygroups->revoke()
*/
public function testRevokeSinglePort()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. "\r\n"
. " true\r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->revokeIp('MyGroup', 'tcp', '80', '80', '0.0.0.0/0');
$this->assertTrue($return);
}
public function testRevokePortRange()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. "\r\n"
. " true\r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->revokeIp('MyGroup', 'tcp', '6000', '7000', '0.0.0.0/0');
$this->assertTrue($return);
}
public function testRevokeSecurityGroupName()
{
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Server: hi\r\n"
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
. "Status: 200 OK\r\n"
. "Content-type: application/xml; charset=utf-8\r\n"
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
. "Connection: close\r\n"
. "\r\n"
. "\r\n"
. "\r\n"
. " true\r\n"
. "\r\n";
$this->adapter->setResponse($rawHttpResponse);
$return = $this->Zend_Service_Amazon_Ec2_Securitygroups->revokeGroup('MyGroup', 'groupname', '15333848');
$this->assertTrue($return);
}
}