Add ApiKey model, which allows to create and and rotate API keys. These keys can be linked to a project or to inference endpoints.
24 lines
799 B
Ruby
24 lines
799 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "spec_helper"
|
|
|
|
RSpec.describe ApiKey do
|
|
describe "ApiKey" do
|
|
let(:prj) {
|
|
Project.create_with_id(name: "test-project")
|
|
}
|
|
|
|
it "can be created and rotated" do
|
|
expect(prj.api_keys.count).to eq 0
|
|
api_key = described_class.create_with_id(owner_table: "project", owner_id: prj.id, used_for: "inference_endpoint")
|
|
expect(prj.reload.api_keys.count).to eq 1
|
|
key = api_key.key
|
|
api_key.rotate
|
|
expect(api_key.key).not_to eq key
|
|
end
|
|
|
|
it "can be created and rotated2" do
|
|
expect { described_class.create_with_id(owner_table: "invalid-owner", owner_id: "2d1784a8-f70d-48e7-92b1-3f428381d62f", used_for: "inference_endpoint") }.to raise_error("Invalid owner_table: invalid-owner")
|
|
end
|
|
end
|
|
end
|