public function testGetModules() { $configuration = new Configuration('./Tests/data/getPost', 'test', new Temp()); $modules = $configuration->getModules(); $modulesCfg = YamlFile::create(ROOT_PATH . '/config/modules.yml')->getData(); foreach ($modulesCfg as $moduleCfg) { self::assertInstanceOf($moduleCfg['class'], $modules[$moduleCfg['type']][$moduleCfg['level']]); } }
public function testCreateOauth2Login() { $ymlConfig = YamlFile::create(ROOT_PATH . '/tests/data/oauth20login/config.yml'); $config = new Config('testApp', 'testCfg', []); $api = $ymlConfig->get('parameters', 'api'); $authorization = $ymlConfig->get('authorization'); $oauth = Api::createAuth($api, $config, $authorization); self::assertInstanceOf('\\Keboola\\GenericExtractor\\Authentication\\OAuth20Login', $oauth); }
/** * @param string $path * @return string class name. */ protected function addModule($path) { $config = YamlFile::create($path)->getData(); // TODO check for type&class $modulesYml = YamlFile::create(ROOT_PATH . '/config/modules.yml', 'w'); $modules = $modulesYml->getData(); $modules[] = $config; $modulesYml->setData($modules); $modulesYml->save(); return $config['class']; }
/** * @return $modules * @throws ApplicationException * @todo 'tis flawed - the path shouldn't be hardcoded for tests */ public function getModules() { $modules = ['response' => []]; try { $modulesCfg = YamlFile::create(ROOT_PATH . '/config/modules.yml')->getData(); } catch (FileNotFoundException $e) { $modulesCfg = []; } foreach ($modulesCfg as $moduleCfg) { $module = $this->createModule($moduleCfg); if (isset($modules[$module['type']][$module['level']])) { throw new ApplicationException("Multiple modules cannot share the same 'level'", 0, null, ['newModule' => $moduleCfg['class'], 'existingModule' => gettype($modules[$module['type']][$module['level']])]); } $modules[$module['type']][$module['level']] = $module['class']; } foreach ($modules as $type => &$typeModules) { ksort($typeModules); } return $modules; }
public function testMACAuth() { $config = YamlFile::create(ROOT_PATH . '/tests/data/oauth20mac/config.yml'); // FIXME base_url from cfg $client = new Client(['base_url' => 'http://example.com']); $restClient = new RestClient($client); $auth = new OAuth20($config->get('authorization'), $config->get('parameters', 'api', 'authentication'), new Builder()); $auth->authenticateClient($restClient); $request = $client->createRequest('GET', '/resource?k=v'); self::sendRequest($client, $request); $authData = json_decode($config->get('authorization', 'oauth_api', 'credentials', '#data')); $authHeader = $request->getHeader('Authorization'); $match = preg_match('/MAC id="testToken", ts="([0-9]{10})", nonce="([0-9a-zA-Z]{16})", mac="([0-9a-zA-Z]{32})"/', $authHeader, $matches); if (1 !== $match) { throw new \Exception("MAC Header does not match the expected pattern"); } $timestamp = $matches[1]; $nonce = $matches[2]; $macString = join("\n", [$timestamp, $nonce, strtoupper($request->getMethod()), $request->getResource(), $request->getHost(), $request->getPort(), "\n"]); $expectedAuthHeader = sprintf('MAC id="%s", ts="%s", nonce="%s", mac="%s"', $authData->access_token, $timestamp, $nonce, md5(hash_hmac('sha256', $macString, $authData->mac_secret))); self::assertEquals($expectedAuthHeader, $authHeader); // Header gets last newline trimmed self::assertEquals($macString, $request->getHeader('Test') . PHP_EOL . PHP_EOL); }
/** * @expectedException Keboola\Juicer\Exception\ApplicationException * @expectedExceptionMessage Error creating file '/asd/123' */ public function testCreateWError() { $yamlFile = YamlFile::create('/asd/123', 'w'); }
/** * @param string $filePath * @param string $path,.. */ protected function getYaml($filePath) { $path = func_get_args(); $filePath = array_shift($path); if (empty($this->yamlFiles[$filePath])) { $this->yamlFiles[$filePath] = YamlFile::create($this->dataDir . $filePath); } return call_user_func_array([$this->yamlFiles[$filePath], 'get'], $path); }