Path: blob/master/spec/api/metasploit_api_app_spec.rb
70321 views
require 'spec_helper'1require 'rack/test'23RSpec.describe Msf::WebServices::MetasploitApiApp do4include Rack::Test::Methods5include_context 'Msf::DBManager'67let(:app) { described_class.new }89before(:example) do10header 'Content-Type', 'application/json'11end1213describe 'host authorization' do14it 'does not reject requests with a 403 Host not permitted error' do15get '/api/v1/hosts'16expect(last_response.status).not_to eq(403)17expect(last_response.body).not_to include('Host not permitted')18end19end2021describe 'authentication' do22it 'does not return 200 for unauthenticated requests to protected endpoints' do23get '/api/v1/hosts'24expect(last_response.status).not_to eq(200)25end2627it 'returns a JSON response body' do28get '/api/v1/hosts'29expect { JSON.parse(last_response.body) }.not_to raise_error30end31end3233describe 'response headers' do34it 'uses lowercase header keys' do35get '/api/v1/hosts'36raw_keys = last_response.headers.keys37raw_keys.each do |key|38expect(key).to eq(key.downcase), "Expected header '#{key}' to be lowercase"39end40end41end42end434445