Open greg0ire opened 9 years ago
How to configure the url from localhost:80
?
Figured it out, to use https
, could you do the same...
Behat\WebApiExtension:
base_url: http://localhost:8000
Hum… why port 8000 ? I do not understand what you are trying to do…
Just what my dev is currently on. But no reason why you could not do https
to overwrite the default.
E.g.
Behat\WebApiExtension:
base_url: https://localhost
This what I did, and then I got errors because guzzle was checking the server certificate.
Oh I see. I will try to investigate later on. Otherwise hopefully someone else has the answer?
According to Guzzle default code, it will check the Cert...
protected function getDefaultOptions()
{
$settings = [
'allow_redirects' => true,
'exceptions' => true,
'decode_content' => true,
'verify' => __DIR__ . '/cacert.pem'
];
// Use the bundled cacert if it is a regular file, or set to true if
// using a phar file (because curL and the stream wrapper can't read
// cacerts from the phar stream wrapper). Favor the ini setting over
// the system's cacert.
if (substr(__FILE__, 0, 7) == 'phar://') {
$settings['verify'] = ini_get('openssl.cafile') ?: true;
}
// Use the standard Linux HTTP_PROXY and HTTPS_PROXY if set
if ($proxy = getenv('HTTP_PROXY')) {
$settings['proxy']['http'] = $proxy;
}
if ($proxy = getenv('HTTPS_PROXY')) {
$settings['proxy']['https'] = $proxy;
}
return $settings;
}
When the Guzzle Client is created in the Extension, you can pass it config
....
public function load(ContainerBuilder $container, array $config)
{
$this->loadClient($container, $config);
$this->loadContextInitializer($container, $config);
}
private function loadClient(ContainerBuilder $container, $config)
{
$definition = new Definition('GuzzleHttp\Client', array($config));
$container->setDefinition(self::CLIENT_ID, $definition);
}
Hope that helps a bit
@eddiejaoude : I saw that, but it doesn't help because $config
is being validated in the method above load()
, and as you can see, for the moment, only base_url
is allowed in config
. Nothing else. This is the point of this issue, I think maybe more things should be allowed.
Here is my work around (to set the allow_redirects
setting):
<?php
namespace Escapee\CoreBundle\Behat;
use Behat\WebApiExtension\ServiceContainer\WebApiExtension as BaseWebApiExtension;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
class WebApiExtension extends BaseWebApiExtension
{
/**
* {@inheritdoc}
*/
public function configure(ArrayNodeDefinition $builder)
{
parent::configure($builder);
$builder
->children()
->arrayNode('defaults')
->children()
->scalarNode('allow_redirects')
->defaultTrue()
->end()
->end()
->end()
->end();
}
}
behat.yml
:
default:
formatters:
progress: ~
extensions:
Escapee\CoreBundle\Behat\WebApiExtension:
defaults:
allow_redirects: false
Note, I now use https://github.com/teaandcode/behat-guzzle-extension
@stof : I made #32 to solve the particular ssl problem, that must be quite common.
I'm testing an API that I just moved to
https
, and since I'm using a self-signed-certificate, guzzle gives me errors. Maybe the verify option should be set to false by default, and maybe it should even be configurable (not sure why though).Here is how I worked around this problem.