From 637bd743ce6679e71fe846c28446f08e21296bc6 Mon Sep 17 00:00:00 2001 From: Filipa Andrade Date: Thu, 15 Oct 2026 16:23:31 +0100 Subject: [PATCH 1/2] Add conformance runner for the cross-SDK parity suite --- conformance/run.php | 147 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 conformance/run.php diff --git a/conformance/run.php b/conformance/run.php new file mode 100644 index 0000000..e5acbf6 --- /dev/null +++ b/conformance/run.php @@ -0,0 +1,147 @@ + $v) { + $lower[strtolower((string) $k)] = $v; + } + $wa = null; + if (isset($lower['www-authenticate']) && preg_match('/error="([^"]+)"/', $lower['www-authenticate'], $m)) { + $wa = $m[1]; + } + $link = null; + if (isset($lower['link']) && preg_match('/<([^>]+)>/', $lower['link'], $m)) { + $link = $m[1]; + } + return [ + 'www_authenticate_error' => $wa, + 'link_license_url' => $link, + 'x_rsl_status' => $lower['x-rsl-status'] ?? null, + 'x_rsl_reason' => $lower['x-rsl-reason'] ?? null, + ]; +} + +function surface_verify(array $in): array +{ + $jwks = new JwksProvider(MOCK_ORIGIN, new HttpClient(), false); + $verifier = new LicenseTokenVerifier($jwks, MOCK_ORIGIN, false); + $res = $verifier->verify($in['token'] ?? '', $in['resource_url']); + if ($res->valid) { + return ['valid' => true, 'reason' => null]; + } + return ['valid' => false, 'reason' => $res->reason?->value]; +} + +function surface_enforce(array $in): array +{ + SupertabConnect::resetInstance(); + SupertabConnect::setBaseUrl(MOCK_ORIGIN); + $connect = new SupertabConnect( + apiKey: 'test', + enforcement: EnforcementMode::from(strtolower((string) $in['enforcement'])), + botDetector: empty($in['use_default_bot_detector']) ? null : new DefaultBotDetector(), + ); + + $req = $in['request']; + $headers = []; + foreach (($req['headers'] ?? []) as $k => $v) { + $headers[strtolower((string) $k)] = $v; + } + $ctx = new RequestContext( + url: $req['url'], + authorizationHeader: $headers['authorization'] ?? null, + userAgent: $headers['user-agent'] ?? null, + accept: $headers['accept'] ?? null, + acceptLanguage: $headers['accept-language'] ?? null, + secChUa: $headers['sec-ch-ua'] ?? null, + headers: $headers, + ); + + $res = $connect->handleRequest($ctx); + $status = ($res instanceof BlockResult || $res instanceof RespondResult) ? $res->status : null; + return [ + 'action' => $res->action->value, + 'status' => $status, + 'headers' => rsl_headers($res->headers), + ]; +} + +function surface_customer_match(array $in): array +{ + // PHP has no usage/serverless path, so this is obtain's own endpoint selection (private, reached via a bound closure). + $blocks = LicenseXmlParser::parseContentElements($in['license_xml'], false); + $client = new LicenseTokenClient(new HttpClient(), false, null, MOCK_ORIGIN); + $endpoint = (fn (string $url) => $this->selectTokenEndpoint($blocks, $url, $this->buildOrigin($url))) + ->call($client, $in['resource_url']); + if (! $endpoint->matched) { + return ['matched' => false, 'matched_url_pattern' => null, 'token_server' => null, 'requires_token' => false]; + } + return [ + 'matched' => true, + 'matched_url_pattern' => $endpoint->scope, + 'token_server' => $endpoint->server, + 'requires_token' => true, + ]; +} + +function surface_customer_obtain(array $in): array +{ + try { + $token = SupertabConnect::obtainLicenseToken( + $in['client_id'], + $in['client_secret'], + $in['resource_url'], + ); + } catch (\Throwable $e) { + return ['outcome' => 'error']; + } + return ['outcome' => $token !== '' ? 'mint' : 'no_token']; +} + +$scn = json_decode(file_get_contents('php://stdin'), true); +$surface = $scn['surface']; +$in = $scn['input']; + +$out = match ($surface) { + 'verify' => surface_verify($in), + 'enforce' => surface_enforce($in), + 'customer-match' => surface_customer_match($in), + 'customer-obtain' => surface_customer_obtain($in), + default => null, +}; + +if ($out === null) { + fwrite(STDERR, "unhandled surface: {$surface}\n"); + exit(2); +} + +echo json_encode($out, JSON_UNESCAPED_SLASHES); From 83bf5eeceebbd22a00dd40d318ba7f774cb6a6cf Mon Sep 17 00:00:00 2001 From: Filipa Andrade Date: Fri, 16 Oct 2026 08:39:12 +0100 Subject: [PATCH 2/2] Point the customer-obtain surface at the mock API --- conformance/run.php | 1 + 1 file changed, 1 insertion(+) diff --git a/conformance/run.php b/conformance/run.php index e5acbf6..d6aac5e 100644 --- a/conformance/run.php +++ b/conformance/run.php @@ -120,6 +120,7 @@ function surface_customer_obtain(array $in): array $in['client_id'], $in['client_secret'], $in['resource_url'], + baseUrl: MOCK_ORIGIN, ); } catch (\Throwable $e) { return ['outcome' => 'error'];