File: digest_auth_spec.rb

package info (click to toggle)
ruby-rack-test 0.7.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 296 kB
  • sloc: ruby: 1,900; makefile: 5
file content (46 lines) | stat: -rw-r--r-- 1,196 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require "spec_helper"

describe Rack::Test::Session do
  context "HTTP Digest authentication" do

    def app
      app = Rack::Auth::Digest::MD5.new(Rack::Test::FakeApp.new) do |username|
        { 'alice' => 'correct-password' }[username]
      end
      app.realm = 'WallysWorld'
      app.opaque = 'this-should-be-secret'
      app
    end

    it 'incorrectly authenticates GETs' do
      digest_authorize 'foo', 'bar'
      get '/'
      expect(last_response).to be_challenge
    end

    it "correctly authenticates GETs" do
      digest_authorize "alice", "correct-password"
      response = get "/"
      expect(response).to be_ok
    end

    it "correctly authenticates GETs with params" do
      digest_authorize "alice", "correct-password"
      response = get "/", "foo" => "bar"
      expect(response).to be_ok
    end

    it "correctly authenticates POSTs" do
      digest_authorize "alice", "correct-password"
      response = post "/"
      expect(response).to be_ok
    end

    it "returns a re-challenge if authenticating incorrectly" do
      digest_authorize "alice", "incorrect-password"
      response = get "/"
      expect(response).to be_challenge
    end

  end
end