Cloudflare-API
view release on metacpan or search on metacpan
};
local *Cloudflare::API::r2=sub { return bless({}, 'Cloudflare::API::R2') };
local *Cloudflare::API::R2::list_buckets_page_response=sub {
die "stop after client creation\n"
};
local *Cloudflare::API::workers=sub { return bless({}, 'Cloudflare::API::Workers') };
local *Cloudflare::API::Workers::list_routes_page_response=sub {
die "stop after client creation\n"
};
{
local @ARGV=qw(--auth=wrangler --resource r2 --action list_buckets);
$error=eval { main(\@ARGV); 1 };
}
ok(!$error && $@=~/stop after client creation/,
'Wrangler authentication reaches an account-scoped request');
is($client_opt{'token'}, 'oauth-test-token', 'Wrangler token passed to client');
is($client_opt{'account_id'}, 'account-id', 'Wrangler account ID passed to client');
$ENV{'MOCK_WRANGLER_WHOAMI_JSON'}='invalid';
%client_opt=();
{
local @ARGV=qw(--auth=wrangler --account-id explicit-id --resource r2 --action list_buckets);
$error=eval { main(\@ARGV); 1 };
}
ok(!$error && $@=~/stop after client creation/,
'explicit account ID skips Wrangler account discovery');
is($client_opt{'account_id'}, 'explicit-id', 'explicit account ID takes precedence');
$ENV{'MOCK_WRANGLER_WHOAMI_JSON'}='invalid';
%client_opt=();
{
local @ARGV=qw(--auth=wrangler --resource workers --action list_routes --arg zone-id);
$error=eval { main(\@ARGV); 1 };
}
ok(!$error && $@=~/stop after client creation/,
'zone-scoped Worker route action skips Wrangler account discovery');
ok(!exists($client_opt{'account_id'}), 'zone-scoped action needs no account ID');
}
($exit, $output)=run_cli(undef, qw(--auth=other --resource accounts --action
list --dump-opt));
isnt($exit, 0, 'unknown authentication source rejected');
( run in 1.326 second using v1.01-cache-2.11-cpan-ac8be02dad9 )