|
61 | 61 | end |
62 | 62 | end |
63 | 63 |
|
| 64 | + it "POST /auth/ldap accepts JSON-style credentials via Rails env and sets omniauth.auth" do |
| 65 | + begin |
| 66 | + OmniAuth.config.test_mode = true |
| 67 | + OmniAuth.config.mock_auth[:ldap] = OmniAuth::AuthHash.new(provider: "ldap", uid: "json-bob", info: {"name" => "Bob"}) |
| 68 | + |
| 69 | + env = { |
| 70 | + "CONTENT_TYPE" => "application/json", |
| 71 | + "action_dispatch.request.request_parameters" => {"username" => "bob", "password" => "secret"}, |
| 72 | + } |
| 73 | + post "/auth/ldap", nil, env |
| 74 | + |
| 75 | + # Follow redirects to callback |
| 76 | + max_redirects = 5 |
| 77 | + redirects = 0 |
| 78 | + while last_response.status == 302 && redirects < max_redirects |
| 79 | + follow_redirect! |
| 80 | + redirects += 1 |
| 81 | + end |
| 82 | + |
| 83 | + expect(last_response.status).to eq 200 |
| 84 | + expect(last_response.body).to include("true") |
| 85 | + ensure |
| 86 | + OmniAuth.config.mock_auth.delete(:ldap) |
| 87 | + OmniAuth.config.test_mode = false |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + it "POST /auth/ldap/callback with JSON missing username and password redirects with missing_credentials" do |
| 92 | + env = { |
| 93 | + "CONTENT_TYPE" => "application/json", |
| 94 | + "action_dispatch.request.request_parameters" => {}, |
| 95 | + } |
| 96 | + post "/auth/ldap/callback", nil, env |
| 97 | + |
| 98 | + expect(last_response.status).to eq 302 |
| 99 | + expect(last_response.headers["Location"]).to match(/missing_credentials/) |
| 100 | + end |
| 101 | + |
| 102 | + it "POST /auth/ldap/callback with JSON username but missing password redirects with missing_credentials" do |
| 103 | + env = { |
| 104 | + "CONTENT_TYPE" => "application/json", |
| 105 | + "action_dispatch.request.request_parameters" => {"username" => "bob"}, |
| 106 | + } |
| 107 | + post "/auth/ldap/callback", nil, env |
| 108 | + |
| 109 | + expect(last_response.status).to eq 302 |
| 110 | + expect(last_response.headers["Location"]).to match(/missing_credentials/) |
| 111 | + end |
| 112 | + |
64 | 113 | it "honors SCRIPT_NAME when mounted under a subdirectory for redirect to callback" do |
65 | 114 | begin |
66 | 115 | OmniAuth.config.test_mode = true |
|
0 commit comments