Kérésre: minden magyarázó komment kikerült a forrásfájlokból — 89 Ruby, 16 TypeScript, 14 Vue, plusz a CSS/JS/CJS. Nem soralapú kereséssel: a Ruby-t a Ripper tokenizálta, a JS/TS/CSS-t állapotgép járta végig, hogy az URL-ekben, reguláris kifejezésekben és heredocokban álló // és # jelek helyükön maradjanak. Három komment maradt, mert nélkülük nem indul a kód: az entrypoint.sh shebangja, a vite-env.d.ts hármas perjeles referenciája, és a sanitize teszt @vitest-environment direktívája (ez utóbbi a magyarázó része nélkül). Egy helyen kódot is kellett írni: a CommandBlock másolás-hibaágán a komment volt a catch egyetlen tartalma, és üres blokkot az eslint nem enged — a copied jelző visszaállítása került a helyére. A yaml, Dockerfile, Makefile, erb és markdown fájlokat nem érintettem. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
71 lines
2.5 KiB
Ruby
71 lines
2.5 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "GET /api/service", type: :request do
|
|
after { WarpEngine::AccessPolicy.reset! }
|
|
|
|
it "names the engine and its version" do
|
|
get "/api/service"
|
|
|
|
json = JSON.parse(response.body)
|
|
expect(json["engine"]).to eq("warp_engine")
|
|
expect(json["version"]).to eq(WarpEngine::VERSION)
|
|
expect(response.headers["WarpEngine-Version"]).to eq(WarpEngine::VERSION)
|
|
end
|
|
|
|
it "reports an open catalog as ungated and offering no sign-in" do
|
|
get "/api/service"
|
|
|
|
json = JSON.parse(response.body)
|
|
expect(json["catalog"]).to eq("gated" => false)
|
|
expect(json["auth"]).to be_nil
|
|
end
|
|
|
|
it "reports a configured policy as a catalog that can gate" do
|
|
policy = Class.new do
|
|
def visible_software_scope(subject: nil) = WarpEngine::Software.all
|
|
def access_for(software:, subject: nil) = WarpEngine::Access::OPEN
|
|
def authorize_download(asset: nil, subject: nil, request: nil) = WarpEngine::Access::Grant::OPEN
|
|
end.new
|
|
allow(WarpEngine.config).to receive(:access_policy).and_return(policy)
|
|
|
|
get "/api/service"
|
|
|
|
expect(JSON.parse(response.body)["catalog"]).to eq("gated" => true)
|
|
end
|
|
|
|
describe "with a client identity configured" do
|
|
before do
|
|
allow(WarpEngine.config).to receive(:access_token_owner_class).and_return("TestOwner")
|
|
allow(WarpEngine.config).to receive(:identity_verification_url).and_return("/devices")
|
|
end
|
|
|
|
it "describes the device flow, so a client needs no addresses of its own" do
|
|
get "/api/service"
|
|
|
|
auth = JSON.parse(response.body)["auth"]
|
|
expect(auth["schemes"]).to eq([ "bearer" ])
|
|
expect(auth["device"]["authorizeUrl"]).to eq("http://www.example.com/api/auth/device")
|
|
expect(auth["device"]["tokenUrl"]).to eq("http://www.example.com/api/auth/device/token")
|
|
expect(auth["device"]["revokeUrl"]).to eq("http://www.example.com/api/auth/token")
|
|
expect(auth["device"]["interval"]).to eq(5)
|
|
end
|
|
|
|
it "makes a configured path absolute against the request" do
|
|
get "/api/service"
|
|
|
|
expect(JSON.parse(response.body)["auth"]["device"]["verificationUrl"])
|
|
.to eq("http://www.example.com/devices")
|
|
end
|
|
|
|
it "leaves an absolute verification URL alone" do
|
|
allow(WarpEngine.config).to receive(:identity_verification_url)
|
|
.and_return("https://accounts.example.org/devices")
|
|
|
|
get "/api/service"
|
|
|
|
expect(JSON.parse(response.body)["auth"]["device"]["verificationUrl"])
|
|
.to eq("https://accounts.example.org/devices")
|
|
end
|
|
end
|
|
end
|