Skip to content
Browse files

Added some basic tests

  • Loading branch information...
1 parent ab2162c commit a2375594630902465ec956dcc3766ea63211cb18 @jamtur01 committed
Showing with 67 additions and 1 deletion.
  1. +2 −0 .rspec
  2. +4 −1 psigner.gemspec
  3. +33 −0 spec/psigner_spec.rb
  4. +28 −0 spec/spec_helper.rb
View
2 .rspec
@@ -0,0 +1,2 @@
+--colour
+--format progress
View
5 psigner.gemspec
@@ -16,5 +16,8 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_dependency "sinatra"
+ s.add_development_dependency "sinatra"
+ s.add_development_dependency "mocha"
+ s.add_development_dependency "rspec"
+ s.add_development_dependency "rack-test"
end
View
33 spec/psigner_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe Psigner::Application do
+
+ describe "GET '/api/sign'" do
+ it "should fail" do
+ get '/'
+ last_response.should_not be_ok
+ end
+ end
+
+ describe "POST '/api/sign'" do
+ it "should fail to get the API signing page without parameters" do
+ post '/api/sign'
+ last_response.status.should == 400
+ end
+
+ it "should fail to get the API signing page with only one parameter" do
+ post '/api/sign', params = { "secret" => "SHAREDSECRET" }
+ last_response.status.should == 400
+ end
+
+ it "should get the API signing page" do
+ post '/api/sign', params = { "secret" => "SHAREDSECRET", "certname" => "bob" }
+ last_response.status.should == 200
+ end
+
+ it "should fail with incorrect shared secret" do
+ post '/api/sign', params = { "secret" => "NOSHAREDSECRET", "certname" => "bob" }
+ last_response.status.should == 401
+ end
+ end
+end
View
28 spec/spec_helper.rb
@@ -0,0 +1,28 @@
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+
+require 'psigner'
+require 'rspec'
+require 'rack/test'
+
+set :environment, :test
+set :run, false
+set :raise_errors, true
+set :logging, false
+
+RSpec.configure do |config|
+ config.include Rack::Test::Methods
+ config.mock_framework = :mocha
+end
+
+ENV['RACK_ENV'] = "test"
+
+def app
+ @app ||= Psigner::Application
+end
+
+# quick convenience methods..
+
+def fixtures_path
+ "#{File.dirname(File.expand_path(__FILE__))}/fixtures"
+end

0 comments on commit a237559

Please sign in to comment.
Something went wrong with that request. Please try again.