-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Authenticate requests to Audiences endpoints (#438)
Authenticate requests to Audiences contexts and SCIM proxy APIs - **Authenticate Audiences requests** - **Add authentication specs for contexts controller**
- Loading branch information
Showing
13 changed files
with
173 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: .. | ||
specs: | ||
audiences (1.3.1) | ||
audiences (1.4.0) | ||
rails (>= 6.0) | ||
|
||
GEM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: .. | ||
specs: | ||
audiences (1.3.1) | ||
audiences (1.4.0) | ||
rails (>= 6.0) | ||
|
||
GEM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: .. | ||
specs: | ||
audiences (1.3.1) | ||
audiences (1.4.0) | ||
rails (>= 6.0) | ||
|
||
GEM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Audiences | ||
VERSION = "1.3.1" | ||
VERSION = "1.4.0" | ||
end |
14 changes: 14 additions & 0 deletions
14
audiences/spec/controllers/authenticated_endpoint_examples.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.shared_examples "authenticated endpoint" do | ||
routes { Audiences::Engine.routes } | ||
|
||
it "requires authentication" do | ||
config_before = Audiences.config.authenticate | ||
Audiences.config.authenticate = ->(*) { false } | ||
|
||
expect(subject).to have_http_status(:unauthorized) | ||
ensure | ||
Audiences.config.authenticate = config_before | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
require_relative "authenticated_endpoint_examples" | ||
|
||
RSpec.describe Audiences::ScimProxyController do | ||
routes { Audiences::Engine.routes } | ||
|
||
context "GET /audiences/scim" do | ||
let(:resource_query) { double } | ||
before do | ||
allow(Audiences::Scim).to( | ||
receive(:resource) | ||
.with(:MyResources) | ||
.and_return(resource_query) | ||
) | ||
end | ||
|
||
it_behaves_like "authenticated endpoint" do | ||
subject { get :get } | ||
end | ||
|
||
it "returns the Resources key from the response" do | ||
allow(resource_query).to receive(:query).and_return({ "response" => "body" }) | ||
|
||
get :get, params: { scim_path: "MyResources", filter: "name eq John" } | ||
|
||
expect(response.parsed_body).to eq({ "response" => "body" }) | ||
end | ||
|
||
it "proxies queries with arguments" do | ||
expect(resource_query).to( | ||
receive(:query) | ||
.with(filter: "name eq John", startIndex: "12", count: "21") | ||
.and_return({ "response" => "body" }) | ||
) | ||
|
||
get :get, params: { scim_path: "MyResources", count: 21, startIndex: 12, filter: "name eq John" } | ||
|
||
expect(response.parsed_body).to eq({ "response" => "body" }) | ||
end | ||
|
||
it "removes the schemas and meta from the resources" do | ||
allow(resource_query).to receive(:query).and_return({ | ||
"response" => "body", | ||
"schemas" => ["schema:a"], | ||
"meta" => "meta", | ||
}) | ||
|
||
get :get, params: { scim_path: "MyResources", filter: "name eq John" } | ||
|
||
expect(response.parsed_body).to eq({ "response" => "body" }) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.