move common test data to contracts/

This commit is contained in:
2026-11-10 09:53:47 +03:00
parent 219448ccfb
commit 1bc688055a
3 changed files with 74 additions and 15 deletions
@@ -2,15 +2,21 @@ require "rails_helper"
RSpec.describe InternalSignatureService do
let(:secret) { "test-secret-key-base" }
let(:body) { '{"status":"player1_won","duration_seconds":42}' }
let(:path) { "/api/internal/matches/abc/result" }
let(:timestamp) { 1_700_000_000 }
it "produces a stable, cross-implementation signature" do
# Vector shared with the game-server (Go) test suite. Do not change the
# formula without updating both sides.
expect(described_class.sign(body, path, secret: secret, timestamp: timestamp))
.to eq("e0a7f8b5508639b1afe604b41f00070dd282d02b6444db5b4856959f175e8361")
# Vectors are shared with the game-server (Go) test suite via
# contracts/test_signature_vectors.json — the single source of truth for
# the wire format. Do not change the formula without updating both sides.
vectors_file = Rails.root.join("..", "contracts", "test_signature_vectors.json")
vectors = JSON.parse(File.read(vectors_file))["vectors"]
expect(vectors).not_to be_empty
vectors.each do |vector|
expect(described_class.sign(vector["body"], vector["path"],
secret: vector["secret"], timestamp: vector["timestamp"]))
.to eq(vector["signature_hex"]),
"signature vector #{vector["name"].inspect} does not match"
end
end
describe ".valid?" do