Compare commits
10 Commits
0e4ab60d77
...
f937f2b426
| Author | SHA1 | Date | |
|---|---|---|---|
| f937f2b426 | |||
| b127c3cba8 | |||
| 3039ddc2ec | |||
| 6d9ea6584d | |||
| fde083f36f | |||
| 255d0189ab | |||
| cbc0b936f8 | |||
| f1e1c8fd18 | |||
| 8b1a5ca4a2 | |||
| 3c88ccd4cc |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,8 @@
|
|||||||
vendor
|
vendor
|
||||||
build
|
build
|
||||||
cache
|
cache
|
||||||
|
.cache
|
||||||
|
.config
|
||||||
|
.local
|
||||||
*.phar
|
*.phar
|
||||||
|
.composer
|
||||||
1
.phpunit.result.cache
Normal file
1
.phpunit.result.cache
Normal file
File diff suppressed because one or more lines are too long
@@ -9,7 +9,8 @@ namespace CloudObjects\SDK\AccountGateway;
|
|||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
use ML\JsonLD\Document, ML\JsonLD\JsonLD, ML\JsonLD\Node;
|
use ML\JsonLD\Document, ML\JsonLD\JsonLD, ML\JsonLD\Node;
|
||||||
use Symfony\Component\HttpFoundation\Request, Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Request, Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory;
|
use Nyholm\Psr7\Factory\Psr17Factory;
|
||||||
|
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
|
||||||
use GuzzleHttp\Client, GuzzleHttp\HandlerStack, GuzzleHttp\Middleware;
|
use GuzzleHttp\Client, GuzzleHttp\HandlerStack, GuzzleHttp\Middleware;
|
||||||
use Psr\Http\Message\RequestInterface, Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\RequestInterface, Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
@@ -110,8 +111,11 @@ class AccountContext {
|
|||||||
new IRI('aauid:'.$request->headers->get('C-AAUID')),
|
new IRI('aauid:'.$request->headers->get('C-AAUID')),
|
||||||
$request->headers->get('C-Access-Token'));
|
$request->headers->get('C-Access-Token'));
|
||||||
|
|
||||||
$psr7Factory = new DiactorosFactory;
|
// Convert HTTP Foundation to PSR17
|
||||||
$context->parsePsrRequest($psr7Factory->createRequest($request));
|
// based on: https://symfony.com/doc/current/components/psr7.html#converting-from-httpfoundation-objects-to-psr-7
|
||||||
|
$psr17Factory = new Psr17Factory;
|
||||||
|
$psrHttpFactory = new PsrHttpFactory($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);
|
||||||
|
$context->parsePsrRequest($psrHttpFactory->createRequest($request));
|
||||||
|
|
||||||
return $context;
|
return $context;
|
||||||
}
|
}
|
||||||
|
|||||||
17
CloudObjects/SDK/CustomCacheAndLogInterface.php
Normal file
17
CloudObjects/SDK/CustomCacheAndLogInterface.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
namespace CloudObjects\SDK;
|
||||||
|
|
||||||
|
interface CustomCacheAndLogInterface {
|
||||||
|
|
||||||
|
public function logInfoWithTime($message, $ts);
|
||||||
|
|
||||||
|
public function getFromCacheCustom($id);
|
||||||
|
|
||||||
|
public function putIntoCacheCustom($id, $data, $ttl);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ use CloudObjects\SDK\AccountGateway\AccountContext;
|
|||||||
/**
|
/**
|
||||||
* The ObjectRetriever provides access to objects on CloudObjects.
|
* The ObjectRetriever provides access to objects on CloudObjects.
|
||||||
*/
|
*/
|
||||||
class ObjectRetriever {
|
class ObjectRetriever implements CustomCacheAndLogInterface {
|
||||||
|
|
||||||
use LoggerAwareTrait;
|
use LoggerAwareTrait;
|
||||||
|
|
||||||
@@ -107,19 +107,31 @@ class ObjectRetriever {
|
|||||||
$this->client = new Client($options);
|
$this->client = new Client($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function logInfoWithTime($message, $ts) {
|
public function logInfoWithTime($message, $ts) {
|
||||||
if (isset($this->logger))
|
if (isset($this->logger))
|
||||||
$this->logger->info($message, [ 'elapsed_ms' => round((microtime(true) - $ts) * 1000) ]);
|
$this->logger->info($message, [ 'elapsed_ms' => round((microtime(true) - $ts) * 1000) ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCacheKey($id) {
|
||||||
|
return $this->options['cache_prefix'].$this->options['auth_ns'].'/'.$id;
|
||||||
|
}
|
||||||
|
|
||||||
private function getFromCache($id) {
|
private function getFromCache($id) {
|
||||||
return (isset($this->cache) && $this->cache->contains($this->options['cache_prefix'].$id))
|
return (isset($this->cache) && $this->cache->contains($this->getCacheKey($id)))
|
||||||
? $this->cache->fetch($this->options['cache_prefix'].$id) : null;
|
? $this->cache->fetch($this->getCacheKey($id)) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function putIntoCache($id, $data, $ttl) {
|
private function putIntoCache($id, $data, $ttl) {
|
||||||
if (isset($this->cache))
|
if (isset($this->cache))
|
||||||
$this->cache->save($this->options['cache_prefix'].$id, $data, $ttl);
|
$this->cache->save($this->getCacheKey($id), $data, $ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFromCacheCustom($id) {
|
||||||
|
return $this->getFromCache('custom/'.$id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putIntoCacheCustom($id, $data, $ttl) {
|
||||||
|
$this->putIntoCache('custom/'.$id, $data, $ttl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -154,21 +154,51 @@ class APIClientFactory {
|
|||||||
'timeout' => self::DEFAULT_TIMEOUT
|
'timeout' => self::DEFAULT_TIMEOUT
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->reader->hasPropertyValue($api, 'wa:supportsAuthenticationMechanism',
|
if ($this->reader->hasProperty($api, 'oauth2:hasAuthorizationServer')) {
|
||||||
'wa:APIKeyAuthentication'))
|
// We have an authorization server for this endpoint/API
|
||||||
|
$authServerCoid = $this->reader->getFirstValueIRI($api, 'oauth2:hasAuthorizationServer');
|
||||||
|
$authServerObject = $this->objectRetriever->getObject($authServerCoid);
|
||||||
|
if (!isset($authServerObject))
|
||||||
|
throw new InvalidObjectConfigurationException("Authorization server object <"
|
||||||
|
. (string)$authServerCoid . "> not available.");
|
||||||
|
|
||||||
|
try {
|
||||||
|
$authServer = new OAuth2AuthServer($authServerObject, $this->objectRetriever);
|
||||||
|
} catch (InvalidObjectConfigurationException $e) {
|
||||||
|
throw new InvalidObjectConfigurationException("Authorization server object <"
|
||||||
|
. (string)$authServerCoid . "> could not be loaded; error: " . $e->getMessage());
|
||||||
|
} catch (Exception $e) {
|
||||||
|
throw new InvalidObjectConfigurationException("Authorization server object <"
|
||||||
|
. (string)$authServerCoid . "> could not be loaded. Its definition may be invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$authServer->configureConsumer($this->namespace);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
throw new InvalidObjectConfigurationException("The namespace <" . $this->namespace->getId()
|
||||||
|
. "> does not contain valid configuration to use the authorization server <"
|
||||||
|
. (string)$authServerCoid . ">.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get access token through the auth server
|
||||||
|
$clientConfig['headers']['Authorization'] = 'Bearer ' . $authServer->getAccessToken();
|
||||||
|
} elseif ($this->reader->hasPropertyValue($api, 'wa:supportsAuthenticationMechanism',
|
||||||
|
'wa:APIKeyAuthentication')) {
|
||||||
|
// API key authentication
|
||||||
$clientConfig = $this->configureAPIKeyAuthentication($api, $clientConfig);
|
$clientConfig = $this->configureAPIKeyAuthentication($api, $clientConfig);
|
||||||
|
} elseif ($this->reader->hasPropertyValue($api, 'wa:supportsAuthenticationMechanism',
|
||||||
elseif ($this->reader->hasPropertyValue($api, 'wa:supportsAuthenticationMechanism',
|
'oauth2:FixedBearerTokenAuthentication')) {
|
||||||
'oauth2:FixedBearerTokenAuthentication'))
|
// Fixed bearer token authentication
|
||||||
$clientConfig = $this->configureBearerTokenAuthentication($api, $clientConfig);
|
$clientConfig = $this->configureBearerTokenAuthentication($api, $clientConfig);
|
||||||
|
} elseif ($this->reader->hasPropertyValue($api, 'wa:supportsAuthenticationMechanism',
|
||||||
elseif ($this->reader->hasPropertyValue($api, 'wa:supportsAuthenticationMechanism',
|
'wa:HTTPBasicAuthentication')) {
|
||||||
'wa:HTTPBasicAuthentication'))
|
// HTTP Basic authentication
|
||||||
$clientConfig = $this->configureBasicAuthentication($api, $clientConfig);
|
$clientConfig = $this->configureBasicAuthentication($api, $clientConfig);
|
||||||
|
} elseif ($this->reader->hasPropertyValue($api, 'wa:supportsAuthenticationMechanism',
|
||||||
elseif ($this->reader->hasPropertyValue($api, 'wa:supportsAuthenticationMechanism',
|
'wa:SharedSecretAuthenticationViaHTTPBasic')) {
|
||||||
'wa:SharedSecretAuthenticationViaHTTPBasic'))
|
// HTTP Basic authentication using shared secrets in CloudObjects Core
|
||||||
$clientConfig = $this->configureSharedSecretBasicAuthentication($api, $clientConfig);
|
$clientConfig = $this->configureSharedSecretBasicAuthentication($api, $clientConfig);
|
||||||
|
}
|
||||||
|
|
||||||
if ($specificClient == false)
|
if ($specificClient == false)
|
||||||
return new Client($clientConfig);
|
return new Client($clientConfig);
|
||||||
|
|||||||
14
CloudObjects/SDK/WebAPI/Exceptions/OAuthFlowException.php
Normal file
14
CloudObjects/SDK/WebAPI/Exceptions/OAuthFlowException.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
namespace CloudObjects\SDK\WebAPI\Exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An Exception that is thrown when an an OAuth flow failed.
|
||||||
|
*/
|
||||||
|
class OAuthFlowException extends \Exception {
|
||||||
|
|
||||||
|
}
|
||||||
143
CloudObjects/SDK/WebAPI/OAuth2AuthServer.php
Normal file
143
CloudObjects/SDK/WebAPI/OAuth2AuthServer.php
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
namespace CloudObjects\SDK\WebAPI;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use ML\JsonLD\Node;
|
||||||
|
use GuzzleHttp\Client;
|
||||||
|
use Webmozart\Assert\Assert,
|
||||||
|
Webmozart\Assert\InvalidArgumentException;
|
||||||
|
use CloudObjects\SDK\NodeReader,
|
||||||
|
CloudObjects\SDK\CustomCacheAndLogInterface;
|
||||||
|
use CloudObjects\SDK\Exceptions\InvalidObjectConfigurationException;
|
||||||
|
|
||||||
|
class OAuth2AuthServer {
|
||||||
|
|
||||||
|
private $reader;
|
||||||
|
private $authServer;
|
||||||
|
private $consumer;
|
||||||
|
private $cacheAndLog;
|
||||||
|
|
||||||
|
private $grantType;
|
||||||
|
private $clientId;
|
||||||
|
private $clientSecret;
|
||||||
|
|
||||||
|
public function __construct(Node $authServer, CustomCacheAndLogInterface $cacheAndLog) {
|
||||||
|
$this->reader = new NodeReader([
|
||||||
|
'prefixes' => [
|
||||||
|
'oauth2' => 'coid://oauth2.co-n.net/'
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Assert::true($this->reader->hasProperty($authServer, 'oauth2:hasTokenEndpoint'),
|
||||||
|
"Authorization Server must have a token endpoint.");
|
||||||
|
Assert::startsWith($this->reader->getFirstValueString($authServer, 'oauth2:hasTokenEndpoint'),
|
||||||
|
"https://",
|
||||||
|
"Token endpoint must be an https:// URL.");
|
||||||
|
Assert::true($this->reader->hasProperty($authServer, 'oauth2:supportsGrantType'),
|
||||||
|
"Authorization Server must support at least one grant type.");
|
||||||
|
Assert::true($this->reader->hasProperty($authServer, 'oauth2:usesClientIDFrom'),
|
||||||
|
"Authorization Server must define client ID property.");
|
||||||
|
Assert::true($this->reader->hasProperty($authServer, 'oauth2:usesClientSecretFrom'),
|
||||||
|
"Authorization Server must define client secret property.");
|
||||||
|
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
throw new InvalidObjectConfigurationException($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->authServer = $authServer;
|
||||||
|
$this->cacheAndLog = $cacheAndLog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureConsumer(Node $consumer) : void {
|
||||||
|
try {
|
||||||
|
Assert::notNull($this->authServer, "Object wasn't initialized correctly.");
|
||||||
|
Assert::notNull($this->cacheAndLog, "Object wasn't initialized correctly.");
|
||||||
|
|
||||||
|
$clientIDProperty = $this->reader->getFirstValueString($this->authServer,
|
||||||
|
'oauth2:usesClientIDFrom');
|
||||||
|
$clientSecretProperty = $this->reader->getFirstValueString($this->authServer,
|
||||||
|
'oauth2:usesClientSecretFrom');
|
||||||
|
|
||||||
|
Assert::true($this->reader->hasProperty($consumer, $clientIDProperty),
|
||||||
|
"Namespace must have Client ID");
|
||||||
|
Assert::true($this->reader->hasProperty($consumer, $clientSecretProperty),
|
||||||
|
"Namespace must have Client Secret");
|
||||||
|
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
throw new InvalidObjectConfigurationException($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->reader->hasPropertyValue($this->authServer,
|
||||||
|
'oauth2:supportsGrantType', 'oauth2:ClientCredentials'))
|
||||||
|
{
|
||||||
|
// No additional conditions for "client_credentials" flow
|
||||||
|
$this->grantType = 'client_credentials';
|
||||||
|
} else {
|
||||||
|
throw new InvalidObjectConfigurationException("No flow/grant_type found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->consumer = $consumer;
|
||||||
|
$this->clientId = $this->reader->getFirstValueString($consumer, $clientIDProperty);
|
||||||
|
$this->clientSecret = $this->reader->getFirstValueString($consumer, $clientSecretProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAccessToken() {
|
||||||
|
try {
|
||||||
|
Assert::notNull($this->authServer, "Object wasn't initialized correctly.");
|
||||||
|
Assert::notNull($this->cacheAndLog, "Object wasn't initialized correctly.");
|
||||||
|
|
||||||
|
Assert::notNull($this->consumer, "Missing consumer.");
|
||||||
|
Assert::notNull($this->grantType, "Missing grant_type.");
|
||||||
|
Assert::notNull($this->clientId, "Missing client_id.");
|
||||||
|
Assert::notNull($this->clientSecret, "Missing client_secret.");
|
||||||
|
|
||||||
|
} catch (InvalidArgumentException $e) {
|
||||||
|
throw new InvalidObjectConfigurationException($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = new Client;
|
||||||
|
$tokenEndpointUrl = $this->reader->getFirstValueString($this->authServer, 'oauth2:hasTokenEndpoint');
|
||||||
|
$params = [
|
||||||
|
'grant_type' => $this->grantType,
|
||||||
|
'client_id' => $this->clientId,
|
||||||
|
'client_secret' => $this->clientSecret
|
||||||
|
];
|
||||||
|
|
||||||
|
switch ($this->grantType) {
|
||||||
|
case "client_credentials":
|
||||||
|
// no additional params needed
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Exception("No flow/grant_type found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$grantCacheKey = sha1(json_encode($params));
|
||||||
|
|
||||||
|
$ts = microtime(true);
|
||||||
|
$tokenResponse = json_decode($this->cacheAndLog->getFromCacheCustom($grantCacheKey), true);
|
||||||
|
|
||||||
|
if (isset($tokenResponse)) {
|
||||||
|
$this->cacheAndLog->logInfoWithTime("Reused access token for <".$this->authServer->getId()."> from cache.", $ts);
|
||||||
|
} else {
|
||||||
|
// Nothing cached, fetch from server
|
||||||
|
$tokenResponse = json_decode($client->post($tokenEndpointUrl, [
|
||||||
|
'form_params' => $params
|
||||||
|
])->getBody(true), true);
|
||||||
|
|
||||||
|
Assert::keyExists($tokenResponse, 'access_token');
|
||||||
|
|
||||||
|
$expiry = isset($tokenResponse['expires_in']) ? $tokenResponse['expires_in'] : 84600;
|
||||||
|
|
||||||
|
$this->cacheAndLog->logInfoWithTime("Retrieved access token for <".$this->authServer->getId()."> from token endpoint and will cache for ".$expiry." seconds.", $ts);
|
||||||
|
$this->cacheAndLog->putIntoCacheCustom($grantCacheKey, json_encode($tokenResponse), $expiry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tokenResponse['access_token'];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
[](https://packagist.org/packages/cloudobjects/sdk) [](https://packagist.org/packages/cloudobjects/sdk)
|
[](https://packagist.org/packages/cloudobjects/sdk) [](https://packagist.org/packages/cloudobjects/sdk)
|
||||||
|
|
||||||
|
[](https://app.buddy.works/cloudobjects/php-sdk/repository/branch/main)
|
||||||
|
|
||||||
The CloudObjects PHP SDK provides simple access to [CloudObjects](https://cloudobjects.io/) from PHP-based applications. It wraps the [Object API](https://coid.link/cloudobjects.io/ObjectAPI/1.0) to fetch objects from the CloudObjects Core database and provides object-based access to their RDF description. A two-tiered caching mechanism (in-memory and Doctrine cache drivers) is included. The SDK also contains a helper class to validate COIDs.
|
The CloudObjects PHP SDK provides simple access to [CloudObjects](https://cloudobjects.io/) from PHP-based applications. It wraps the [Object API](https://coid.link/cloudobjects.io/ObjectAPI/1.0) to fetch objects from the CloudObjects Core database and provides object-based access to their RDF description. A two-tiered caching mechanism (in-memory and Doctrine cache drivers) is included. The SDK also contains a helper class to validate COIDs.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
"doctrine/common" : ">=2.6.1",
|
"doctrine/common" : ">=2.6.1",
|
||||||
"doctrine/cache" : "1.*",
|
"doctrine/cache" : "1.*",
|
||||||
"guzzlehttp/guzzle" : ">=6.0",
|
"guzzlehttp/guzzle" : ">=6.0",
|
||||||
"psr/log": "^1.1",
|
"psr/log": ">=1.1",
|
||||||
"kevinrob/guzzle-cache-middleware": "^3.2",
|
"kevinrob/guzzle-cache-middleware": "^7.0.0",
|
||||||
"webmozart/assert": "^1.6"
|
"webmozart/assert": "^1.6"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -24,16 +24,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require-dev" : {
|
"require-dev" : {
|
||||||
"phpunit/phpunit": ">=4.8.0,<5.0",
|
"phpunit/phpunit": "^10",
|
||||||
"symfony/http-foundation" : ">=4.0",
|
"symfony/http-foundation" : ">=4.0",
|
||||||
"symfony/psr-http-message-bridge" : ">=1.1.0",
|
"symfony/psr-http-message-bridge" : ">=1.1.0",
|
||||||
"zendframework/zend-diactoros" : "~1.8.6",
|
"nyholm/psr7" : "~1.5.1",
|
||||||
"defuse/php-encryption" : "^2.2"
|
"defuse/php-encryption" : "^2.2"
|
||||||
},
|
},
|
||||||
"suggest" : {
|
"suggest" : {
|
||||||
"symfony/http-foundation" : "Required to use parseSymfonyRequest() in AccountContext.",
|
"symfony/http-foundation" : "Required to use parseSymfonyRequest() in AccountContext.",
|
||||||
"symfony/psr-http-message-bridge" : "Required to use parseSymfonyRequest() in AccountContext.",
|
"symfony/psr-http-message-bridge" : "Required to use parseSymfonyRequest() in AccountContext.",
|
||||||
"zendframework/zend-diactoros" : "Required to use parseSymfonyRequest() in AccountContext.",
|
"nyholm/psr7" : "Required to use parseSymfonyRequest() in AccountContext.",
|
||||||
"defuse/php-encryption": "Required to use CryptoHelper"
|
"defuse/php-encryption": "Required to use CryptoHelper"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2865
composer.lock
generated
2865
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit backupGlobals="false"
|
<phpunit backupGlobals="false"
|
||||||
backupStaticAttributes="false"
|
|
||||||
colors="true"
|
colors="true"
|
||||||
convertErrorsToExceptions="true"
|
|
||||||
convertNoticesToExceptions="true"
|
|
||||||
convertWarningsToExceptions="true"
|
|
||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
stopOnFailure="false"
|
stopOnFailure="false"
|
||||||
syntaxCheck="false"
|
|
||||||
bootstrap="./tests/bootstrap.php">
|
bootstrap="./tests/bootstrap.php">
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="OfflineTests">
|
<testsuite name="OfflineTests">
|
||||||
|
|||||||
5
run-docker.sh
Normal file
5
run-docker.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
docker run -d -v .:/root --name cloudobjects-sdk-test cloudobjects/php-build-base:8.3
|
||||||
|
docker exec cloudobjects-sdk-test bash -c "cd /root && composer install"
|
||||||
|
docker exec cloudobjects-sdk-test bash -c "cd /root && vendor/bin/phpunit"
|
||||||
|
docker stop cloudobjects-sdk-test
|
||||||
|
docker rm cloudobjects-sdk-test
|
||||||
@@ -8,7 +8,7 @@ namespace CloudObjects\SDK\AccountGateway;
|
|||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
|
|
||||||
class AAUIDParserTest extends \PHPUnit_Framework_TestCase {
|
class AAUIDParserTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
public function testValidAccountAAUID() {
|
public function testValidAccountAAUID() {
|
||||||
$aauid = new IRI('aauid:abcd1234abcd1234');
|
$aauid = new IRI('aauid:abcd1234abcd1234');
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace CloudObjects\SDK\AccountGateway;
|
|||||||
use GuzzleHttp\Psr7\Request as GuzzlePsrRequest;
|
use GuzzleHttp\Psr7\Request as GuzzlePsrRequest;
|
||||||
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
|
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
|
||||||
|
|
||||||
class AccountContextParseTest extends \PHPUnit_Framework_TestCase {
|
class AccountContextParseTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
public function testParsePsrRequest() {
|
public function testParsePsrRequest() {
|
||||||
$request = new GuzzlePsrRequest('GET', '/', [
|
$request = new GuzzlePsrRequest('GET', '/', [
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ namespace CloudObjects\SDK\AccountGateway;
|
|||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
|
|
||||||
class AccountContextTest extends \PHPUnit_Framework_TestCase {
|
class AccountContextTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $context;
|
private $context;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp(): void {
|
||||||
$this->context = new AccountContext(new IRI('aauid:aaaabbbbccccdddd'), 'DUMMY');
|
$this->context = new AccountContext(new IRI('aauid:aaaabbbbccccdddd'), 'DUMMY');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace CloudObjects\SDK;
|
|||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
|
|
||||||
class COIDParserTest extends \PHPUnit_Framework_TestCase {
|
class COIDParserTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
public function testRootCOID() {
|
public function testRootCOID() {
|
||||||
$coid = new IRI('coid://example.com');
|
$coid = new IRI('coid://example.com');
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
|||||||
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
||||||
use CloudObjects\SDK\ObjectRetriever;
|
use CloudObjects\SDK\ObjectRetriever;
|
||||||
|
|
||||||
class CryptoHelperTest extends \PHPUnit_Framework_TestCase {
|
class CryptoHelperTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $retriever;
|
private $retriever;
|
||||||
private $graph;
|
private $graph;
|
||||||
@@ -22,7 +22,7 @@ class CryptoHelperTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->retriever->setClient(new Client(['handler' => $handler]));
|
$this->retriever->setClient(new Client(['handler' => $handler]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUp() {
|
protected function setUp(): void {
|
||||||
$this->retriever = new ObjectRetriever([
|
$this->retriever = new ObjectRetriever([
|
||||||
'auth_ns' => 'test.cloudobjects.io',
|
'auth_ns' => 'test.cloudobjects.io',
|
||||||
'auth_secret' => 'TEST'
|
'auth_secret' => 'TEST'
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ use InvalidArgumentException;
|
|||||||
use ML\JsonLD\JsonLD;
|
use ML\JsonLD\JsonLD;
|
||||||
use CloudObjects\SDK\ObjectRetriever;
|
use CloudObjects\SDK\ObjectRetriever;
|
||||||
|
|
||||||
class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
class SchemaValidatorTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $schemaValidator;
|
private $schemaValidator;
|
||||||
private $graph;
|
private $graph;
|
||||||
|
|
||||||
public function setUp() {
|
protected function setUp(): void {
|
||||||
$this->schemaValidator = new SchemaValidator(new ObjectRetriever);
|
$this->schemaValidator = new SchemaValidator(new ObjectRetriever);
|
||||||
$this->graph = JsonLD::getDocument('{}')->getGraph();
|
$this->graph = JsonLD::getDocument('{}')->getGraph();
|
||||||
}
|
}
|
||||||
@@ -24,10 +24,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/String'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/String'));
|
||||||
$this->schemaValidator->validateAgainstNode("Test", $node);
|
$this->schemaValidator->validateAgainstNode("Test", $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotString() {
|
public function testNotString() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/String'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/String'));
|
||||||
@@ -38,10 +39,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Number'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Number'));
|
||||||
$this->schemaValidator->validateAgainstNode(3.5, $node);
|
$this->schemaValidator->validateAgainstNode(3.5, $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotNumber() {
|
public function testNotNumber() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Number'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Number'));
|
||||||
@@ -52,10 +54,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Integer'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Integer'));
|
||||||
$this->schemaValidator->validateAgainstNode(12, $node);
|
$this->schemaValidator->validateAgainstNode(12, $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotInteger() {
|
public function testNotInteger() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Integer'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Integer'));
|
||||||
@@ -66,10 +69,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Array'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Array'));
|
||||||
$this->schemaValidator->validateAgainstNode([ 1, 2, "foo" ], $node);
|
$this->schemaValidator->validateAgainstNode([ 1, 2, "foo" ], $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotArray() {
|
public function testNotArray() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Array'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Array'));
|
||||||
@@ -83,10 +87,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'a' => 'A',
|
'a' => 'A',
|
||||||
'b' => 'B'
|
'b' => 'B'
|
||||||
], $node);
|
], $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotObject() {
|
public function testNotObject() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
|
||||||
@@ -105,10 +110,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'a' => 'A',
|
'a' => 'A',
|
||||||
'b' => 'B'
|
'b' => 'B'
|
||||||
], $node);
|
], $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testObjectWithPropertyTypeError() {
|
public function testObjectWithPropertyTypeError() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$stringNode = $this->graph->createNode();
|
$stringNode = $this->graph->createNode();
|
||||||
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
||||||
@@ -136,10 +142,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'a' => 'A',
|
'a' => 'A',
|
||||||
'b' => 'B'
|
'b' => 'B'
|
||||||
], $node);
|
], $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testObjectWithRequiredPropertyTypeError() {
|
public function testObjectWithRequiredPropertyTypeError() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$stringNode = $this->graph->createNode();
|
$stringNode = $this->graph->createNode();
|
||||||
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
||||||
@@ -156,7 +163,7 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testObjectWithRequiredPropertyMissing() {
|
public function testObjectWithRequiredPropertyMissing() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$stringNode = $this->graph->createNode();
|
$stringNode = $this->graph->createNode();
|
||||||
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use ML\IRI\IRI;
|
|||||||
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
||||||
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
||||||
|
|
||||||
class NodeReaderMockTest extends \PHPUnit_Framework_TestCase {
|
class NodeReaderMockTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $retriever;
|
private $retriever;
|
||||||
private $reader;
|
private $reader;
|
||||||
@@ -27,7 +27,7 @@ class NodeReaderMockTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'{"@context":{"co":"coid:\/\/cloudobjects.io\/","rdf":"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#","agws":"coid:\/\/aauid.net\/","rdfs":"http:\/\/www.w3.org\/2000\/01\/rdf-schema#"},"@id":"coid:\/\/cloudobjects.io","@type":["agws:Service","co:Namespace"],"co:isAtRevision":"6-fbea0c90b2c5e5300e4039ed99be9b2d","co:isVisibleTo":{"@id":"co:Public"},"co:recommendsPrefix":"co","co:wasUpdatedAt":{"@type":"http:\/\/www.w3.org\/2001\/XMLSchema#dateTime","@value":"2017-01-16T17:29:22+00:00"},"rdfs:comment":"The CloudObjects namespace defines the essential objects.","rdfs:label":"CloudObjects"}'));
|
'{"@context":{"co":"coid:\/\/cloudobjects.io\/","rdf":"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#","agws":"coid:\/\/aauid.net\/","rdfs":"http:\/\/www.w3.org\/2000\/01\/rdf-schema#"},"@id":"coid:\/\/cloudobjects.io","@type":["agws:Service","co:Namespace"],"co:isAtRevision":"6-fbea0c90b2c5e5300e4039ed99be9b2d","co:isVisibleTo":{"@id":"co:Public"},"co:recommendsPrefix":"co","co:wasUpdatedAt":{"@type":"http:\/\/www.w3.org\/2001\/XMLSchema#dateTime","@value":"2017-01-16T17:29:22+00:00"},"rdfs:comment":"The CloudObjects namespace defines the essential objects.","rdfs:label":"CloudObjects"}'));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp(): void {
|
||||||
$this->retriever = new ObjectRetriever;
|
$this->retriever = new ObjectRetriever;
|
||||||
$this->reader = new NodeReader([
|
$this->reader = new NodeReader([
|
||||||
'prefixes' => [
|
'prefixes' => [
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use ML\IRI\IRI;
|
|||||||
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
||||||
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
||||||
|
|
||||||
class ObjectRetrieverMockTest extends \PHPUnit_Framework_TestCase {
|
class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $retriever;
|
private $retriever;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ class ObjectRetrieverMockTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->retriever->setClient(new Client(['handler' => $handler]));
|
$this->retriever->setClient(new Client(['handler' => $handler]));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp(): void {
|
||||||
$this->retriever = new ObjectRetriever;
|
$this->retriever = new ObjectRetriever;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ use InvalidArgumentException;
|
|||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
use CloudObjects\SDK\ObjectRetriever;
|
use CloudObjects\SDK\ObjectRetriever;
|
||||||
|
|
||||||
class SchemaValidatorPublicTest extends \PHPUnit_Framework_TestCase {
|
class SchemaValidatorPublicTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $schemaValidator;
|
private $schemaValidator;
|
||||||
|
|
||||||
public function setUp() {
|
protected function setUp(): void {
|
||||||
$this->schemaValidator = new SchemaValidator(new ObjectRetriever);
|
$this->schemaValidator = new SchemaValidator(new ObjectRetriever);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,10 +24,11 @@ class SchemaValidatorPublicTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'region' => 'Hessen',
|
'region' => 'Hessen',
|
||||||
'country-name' => 'Germany'
|
'country-name' => 'Germany'
|
||||||
], new IRI('coid://json.co-n.net/Address'));
|
], new IRI('coid://json.co-n.net/Address'));
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotAddress() {
|
public function testNotAddress() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$this->schemaValidator->validateAgainstCOID([
|
$this->schemaValidator->validateAgainstCOID([
|
||||||
'region' => 'Hessen',
|
'region' => 'Hessen',
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ namespace CloudObjects\SDK;
|
|||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
|
|
||||||
class ObjectRetrieverTest extends \PHPUnit_Framework_TestCase {
|
class ObjectRetrieverPublicTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $retriever;
|
private $retriever;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp(): void {
|
||||||
$this->retriever = new ObjectRetriever;
|
$this->retriever = new ObjectRetriever;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user