diff options
| author | mo khan <mo@mokhan.ca> | 2025-06-09 13:51:29 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-06-09 13:51:29 -0600 |
| commit | f42e23ad9847e11e86c77623eb77da3355b6d71b (patch) | |
| tree | 1f1cbb1c1ffe1b10f6bd188afd7ece427d8a0b96 | |
| parent | 14c7a0e3ebf77451662bbbac1915facdec0bca3f (diff) | |
test: switch to rspec
| -rw-r--r-- | .rspec | 1 | ||||
| -rw-r--r-- | Gemfile | 6 | ||||
| -rw-r--r-- | Gemfile.lock | 41 | ||||
| -rwxr-xr-x | bin/cibuild | 1 | ||||
| -rwxr-xr-x | bin/test | 63 | ||||
| -rw-r--r-- | spec/integration/server_spec.rb | 46 | ||||
| -rw-r--r-- | spec/spec_helper.rb | 28 | ||||
| -rw-r--r-- | spec/support/server.rb | 24 |
8 files changed, 149 insertions, 61 deletions
@@ -0,0 +1 @@ +--require spec_helper @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gem "net-hippie", "~> 1.0" +gem "rspec", "~> 3.0" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..a413279 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,41 @@ +GEM + remote: https://rubygems.org/ + specs: + base64 (0.3.0) + diff-lcs (1.6.2) + json (2.12.2) + logger (1.7.0) + net-hippie (1.3.0) + base64 (~> 0.1) + json (~> 2.0) + logger (~> 1.0) + net-http (~> 0.6) + openssl (~> 3.0) + net-http (0.6.0) + uri + openssl (3.3.0) + rspec (3.13.1) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.4) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.5) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.4) + uri (1.0.3) + +PLATFORMS + ruby + x86_64-linux + +DEPENDENCIES + net-hippie (~> 1.0) + rspec (~> 3.0) + +BUNDLED WITH + 2.6.9 diff --git a/bin/cibuild b/bin/cibuild index 391ed8e..2a9dec8 100755 --- a/bin/cibuild +++ b/bin/cibuild @@ -13,5 +13,6 @@ apt update apt install -y mise mise install +bundle install ./bin/test mise exec -- cargo test @@ -1,62 +1,3 @@ -#!/usr/bin/env ruby +#!/bin/sh -require "bundler/inline" - -gemfile do - source "https://rubygems.org" - - gem "minitest", "~> 5.0" - gem "net-hippie", "~> 1.0" -end - -$bind_addr = ENV.fetch("BIND_ADDR", "127.0.0.1:7878") - -pid = Process.spawn({ - "BIND_ADDR" => $bind_addr -}, "mise exec -- cargo run") -sleep 1 - -at_exit do - Process.kill('SIGTERM', pid) - system("killall sts") -end - -require "minitest/autorun" - -class ServerTest < Minitest::Test - attr_reader :base_url, :client - - def setup - @base_url = "http://#{$bind_addr}" - @client = Net::Hippie::Client.new - end - - def test_homepage - response = client.get(base_url + "/") - assert_equal response.code, "200" - end - - def test_not_found - response = client.get(base_url + "/404") - assert_equal "404", response.code - end - - # /.well-known/oauth-authorization-server https://datatracker.ietf.org/doc/html/rfc8414#section-3.1 - def test_metadata - response = client.get(base_url + "/.well-known/oauth-authorization-server") - assert_equal "200", response.code - assert_equal "application/json", response["Content-Type"] - end - - # /token - Token endpoint https://datatracker.ietf.org/doc/html/rfc8693#section-2.3 - def test_token - end - - # /introspect - Token introspection https://datatracker.ietf.org/doc/html/rfc7662#section-2 - def test_introspect - end - - # /revoke - Token revocation # https://datatracker.ietf.org/doc/html/rfc7009#section-2.1 - def test_revoke - end -end +bundle exec rspec diff --git a/spec/integration/server_spec.rb b/spec/integration/server_spec.rb new file mode 100644 index 0000000..1271f05 --- /dev/null +++ b/spec/integration/server_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe "Server" do + let(:base_url) { "http://#{RSpec.configuration.bind_addr}" } + let(:client) { Net::Hippie::Client.new } + + describe "GET /" do + it 'returns OK' do + response = client.get(base_url + "/") + expect(response.code).to eq("200") + end + end + + describe "GET /404" do + it 'returns 404' do + response = client.get(base_url + "/404") + expect(response.code).to eq("404") + end + end + + # https://datatracker.ietf.org/doc/html/rfc8414#section-3.1 + describe "GET /.well-known/oauth-authorization-server" do + it 'returns OK' do + response = client.get(base_url + "/.well-known/oauth-authorization-server") + expect(response.code).to eq("200") + expect(response["Content-Type"]).to eq("application/json") + end + end + + # https://datatracker.ietf.org/doc/html/rfc8693#section-2.3 + describe "POST /token" do + pending + end + + # https://datatracker.ietf.org/doc/html/rfc7662#section-2 + describe "POST /introspect" do + pending + end + + # https://datatracker.ietf.org/doc/html/rfc7009#section-2.1 + describe "POST /revoke" do + pending + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..b7fab03 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require "net/hippie" +require "uri" + +Dir[File.join(Dir.pwd, 'spec/support/**/*.rb')].sort.each { |f| require f } + +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + + config.shared_context_metadata_behavior = :apply_to_host_groups + config.filter_run_when_matching :focus + config.disable_monkey_patching! + config.warnings = true + + if config.files_to_run.one? + config.default_formatter = "doc" + end + + config.order = :random + Kernel.srand config.seed +end diff --git a/spec/support/server.rb b/spec/support/server.rb new file mode 100644 index 0000000..2fea6af --- /dev/null +++ b/spec/support/server.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +RSpec.configure do |config| + config.add_setting :bind_addr + config.bind_addr = ENV.fetch("BIND_ADDR", "127.0.0.1:7878") + + config.add_setting :pid + + config.before :suite do + RSpec.configuration.pid = Process.spawn({ + "BIND_ADDR" => RSpec.configuration.bind_addr, + }, "mise exec -- cargo run") + sleep 1 + end + + config.after :suite do + Process.kill('SIGTERM', RSpec.configuration.pid) + system("killall sts") + end +end + +at_exit do + system("killall sts") +end |
