mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-10-05 22:31:57 +08:00
Previously, the code only worked with Cloudflare User API tokens. Use Account API token endpoints if the GITHUB_CACHE_BLOB_STORAGE_USE_ACCOUNT_TOKEN environment variable is truthy.
34 lines
1.3 KiB
Ruby
34 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe CloudflareClient do
|
|
let(:client) { described_class.new("api_key") }
|
|
|
|
it "create_token" do
|
|
Excon.stub({path: "/client/v4/user/tokens", method: :post}, {status: 200, body: {result: {id: "123", value: "secret"}}.to_json})
|
|
expect(client.create_token("test-token", [{id: "test-policy"}])).to eq(["123", "secret"])
|
|
end
|
|
|
|
it "delete_token" do
|
|
token_id = "123"
|
|
Excon.stub({path: "/client/v4/user/tokens/#{token_id}", method: :delete}, {status: 200})
|
|
expect(client.delete_token(token_id)).to eq(200)
|
|
end
|
|
|
|
describe "when setting Config.github_cache_blob_storage_use_account_token" do
|
|
before do
|
|
expect(Config).to receive(:github_cache_blob_storage_use_account_token).and_return(true)
|
|
expect(Config).to receive(:github_cache_blob_storage_account_id).and_return("XYZ")
|
|
end
|
|
|
|
it "create_token" do
|
|
Excon.stub({path: "/client/v4/accounts/XYZ/tokens", method: :post}, {status: 200, body: {result: {id: "123", value: "secret"}}.to_json})
|
|
expect(client.create_token("test-token", [{id: "test-policy"}])).to eq(["123", "secret"])
|
|
end
|
|
|
|
it "delete_token" do
|
|
token_id = "123"
|
|
Excon.stub({path: "/client/v4/accounts/XYZ/tokens/#{token_id}", method: :delete}, {status: 200})
|
|
expect(client.delete_token(token_id)).to eq(200)
|
|
end
|
|
end
|
|
end
|