mardi 24 novembre 2015

How to mock requests in codeception with fake ip addresses?

I am working on a Laravel 5 application and I have just installed antonioribeiro/firewall to restrict IP addresses to make requests in web service.

Now I am trying to test the same with codeception like so:

<?php 
$I = new ApiTester($scenario);
$I->wantTo('blacklist address and confirm access denied to them');
$I->haveHttpHeader('Authorization', 'Bearer ' . file_get_contents('tests/api/token'));
$I->sendPost('firewall/blacklist', [
    'ip' => '127.0.0.1'
]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['message' => 'IP Blacklisted Successfully']);
$I->seeInDatabase('firewall', [
    "ip_address" => "127.0.0.1",
    "whitelisted" => 0
]);

$I->sendGet('users');
$I->seeResponseIsJson();
$I->seeResponseContainsJson(['message' => 'IP Address Forbidden']);

Since I working on my local machine, I am restricted to use 127.0.0.1 only. How to make requests using codeception with fake ip addresses?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire