-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix limited admin accounts not being able to publish website backends.
Pending changes for website backends weren't being returned to admin accounts with limited scopes (only authorized on specific domains). The reason was that we were inadvertently applying the API backend policy scope to this permission check instead of the website backend policy (so the API backend policy would never consider the website backend authorized). This fixes that issue and adds more test coverage for the admin permissions surrounding website backends in the config publishing process.
- Loading branch information
Showing
10 changed files
with
223 additions
and
5 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
9 changes: 7 additions & 2 deletions
9
src/api-umbrella/web-app/app/policies/website_backend_policy.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
2 changes: 1 addition & 1 deletion
2
...test_pending_changes_admin_permissions.rb → ...pending_changes_admin_permissions_apis.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
74 changes: 74 additions & 0 deletions
74
test/apis/v1/config/test_pending_changes_admin_permissions_websites.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,74 @@ | ||
require_relative "../../../test_helper" | ||
|
||
class Test::Apis::V1::Config::TestPendingChangesAdminPermissionsWebsites < Minitest::Test | ||
include ApiUmbrellaTestHelpers::AdminAuth | ||
include ApiUmbrellaTestHelpers::Setup | ||
include Minitest::Hooks | ||
|
||
def setup | ||
super | ||
setup_server | ||
Api.delete_all | ||
WebsiteBackend.delete_all | ||
ConfigVersion.delete_all | ||
|
||
@localhost_website = FactoryBot.create(:website_backend) | ||
@example_com_website = FactoryBot.create(:example_com_website_backend) | ||
ConfigVersion.publish!(ConfigVersion.pending_config) | ||
end | ||
|
||
def after_all | ||
super | ||
default_config_version_needed | ||
end | ||
|
||
def test_all_websites_for_superuser | ||
response = Typhoeus.get("https://127.0.0.1:9081/api-umbrella/v1/config/pending_changes.json", http_options.deep_merge(admin_token)) | ||
|
||
assert_response_code(200, response) | ||
data = MultiJson.load(response.body) | ||
website_ids = data["config"]["website_backends"]["identical"].map { |website| website["pending"]["_id"] } | ||
assert_includes(website_ids, @localhost_website.id) | ||
assert_includes(website_ids, @example_com_website.id) | ||
end | ||
|
||
def test_permitted_websites_for_limited_admin | ||
localhost_admin = FactoryBot.create(:limited_admin, :groups => [FactoryBot.create(:localhost_root_admin_group, :backend_publish_permission)]) | ||
response = Typhoeus.get("https://127.0.0.1:9081/api-umbrella/v1/config/pending_changes.json", http_options.deep_merge(admin_token(localhost_admin))) | ||
|
||
assert_response_code(200, response) | ||
data = MultiJson.load(response.body) | ||
website_ids = data["config"]["website_backends"]["identical"].map { |website| website["pending"]["_id"] } | ||
assert_includes(website_ids, @localhost_website.id) | ||
end | ||
|
||
def test_excludes_forbidden_websites | ||
localhost_admin = FactoryBot.create(:limited_admin, :groups => [FactoryBot.create(:localhost_root_admin_group, :backend_publish_permission)]) | ||
response = Typhoeus.get("https://127.0.0.1:9081/api-umbrella/v1/config/pending_changes.json", http_options.deep_merge(admin_token(localhost_admin))) | ||
|
||
assert_response_code(200, response) | ||
data = MultiJson.load(response.body) | ||
website_ids = data["config"]["website_backends"]["identical"].map { |website| website["pending"]["_id"] } | ||
refute_includes(website_ids, @example_com_website.id) | ||
end | ||
|
||
def test_exclude_websites_without_publish_permission | ||
unauthorized_localhost_admin = FactoryBot.create(:limited_admin, :groups => [FactoryBot.create(:localhost_root_admin_group, :backend_manage_permission)]) | ||
response = Typhoeus.get("https://127.0.0.1:9081/api-umbrella/v1/config/pending_changes.json", http_options.deep_merge(admin_token(unauthorized_localhost_admin))) | ||
|
||
assert_response_code(200, response) | ||
data = MultiJson.load(response.body) | ||
website_ids = data["config"]["website_backends"]["identical"].map { |website| website["pending"]["_id"] } | ||
assert_equal(0, website_ids.length) | ||
end | ||
|
||
def test_excludes_admins_without_root_url_permissions | ||
localhost_admin = FactoryBot.create(:limited_admin, :groups => [FactoryBot.create(:google_admin_group, :backend_publish_permission)]) | ||
response = Typhoeus.get("https://127.0.0.1:9081/api-umbrella/v1/config/pending_changes.json", http_options.deep_merge(admin_token(localhost_admin))) | ||
|
||
assert_response_code(200, response) | ||
data = MultiJson.load(response.body) | ||
website_ids = data["config"]["website_backends"]["identical"].map { |website| website["pending"]["_id"] } | ||
assert_equal(0, website_ids.length) | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
.../config/test_publish_admin_permissions.rb → ...ig/test_publish_admin_permissions_apis.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
121 changes: 121 additions & 0 deletions
121
test/apis/v1/config/test_publish_admin_permissions_websites.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,121 @@ | ||
require_relative "../../../test_helper" | ||
|
||
class Test::Apis::V1::Config::TestPublishAdminPermissionsWebsites < Minitest::Test | ||
include ApiUmbrellaTestHelpers::AdminAuth | ||
include ApiUmbrellaTestHelpers::Setup | ||
include Minitest::Hooks | ||
|
||
def setup | ||
super | ||
setup_server | ||
Api.delete_all | ||
WebsiteBackend.delete_all | ||
ConfigVersion.delete_all | ||
|
||
@localhost_website = FactoryBot.create(:website_backend) | ||
@example_com_website = FactoryBot.create(:example_com_website_backend) | ||
end | ||
|
||
def after_all | ||
super | ||
default_config_version_needed | ||
end | ||
|
||
def test_superusers_publish_anything | ||
config = { | ||
:website_backends => { | ||
@localhost_website.id => { :publish => "1" }, | ||
@example_com_website.id => { :publish => "1" }, | ||
}, | ||
} | ||
|
||
response = Typhoeus.post("https://127.0.0.1:9081/api-umbrella/v1/config/publish.json", http_options.deep_merge(admin_token).deep_merge({ | ||
:headers => { "Content-Type" => "application/x-www-form-urlencoded" }, | ||
:body => { :config => config }, | ||
})) | ||
|
||
assert_response_code(201, response) | ||
active_config = ConfigVersion.active_config | ||
assert_equal(2, active_config["website_backends"].length) | ||
assert_equal([ | ||
@localhost_website.id, | ||
@example_com_website.id, | ||
].sort, active_config["website_backends"].map { |api| api["_id"] }.sort) | ||
end | ||
|
||
def test_allow_limited_admins_publish_permitted_websites | ||
config = { | ||
:website_backends => { | ||
@localhost_website.id => { :publish => "1" }, | ||
}, | ||
} | ||
|
||
localhost_admin = FactoryBot.create(:limited_admin, :groups => [FactoryBot.create(:localhost_root_admin_group, :backend_publish_permission)]) | ||
response = Typhoeus.post("https://127.0.0.1:9081/api-umbrella/v1/config/publish.json", http_options.deep_merge(admin_token(localhost_admin)).deep_merge({ | ||
:headers => { "Content-Type" => "application/x-www-form-urlencoded" }, | ||
:body => { :config => config }, | ||
})) | ||
|
||
assert_response_code(201, response) | ||
active_config = ConfigVersion.active_config | ||
assert_equal(1, active_config["website_backends"].length) | ||
assert_equal(@localhost_website.id, active_config["website_backends"].first["_id"]) | ||
end | ||
|
||
def test_reject_limited_admins_publish_forbidden_website_backends | ||
config = { | ||
:website_backends => { | ||
@example_com_website.id => { :publish => "1" }, | ||
}, | ||
} | ||
|
||
localhost_admin = FactoryBot.create(:limited_admin, :groups => [FactoryBot.create(:localhost_root_admin_group, :backend_publish_permission)]) | ||
response = Typhoeus.post("https://127.0.0.1:9081/api-umbrella/v1/config/publish.json", http_options.deep_merge(admin_token(localhost_admin)).deep_merge({ | ||
:headers => { "Content-Type" => "application/x-www-form-urlencoded" }, | ||
:body => { :config => config }, | ||
})) | ||
|
||
assert_response_code(403, response) | ||
data = MultiJson.load(response.body) | ||
assert_equal(["errors"], data.keys) | ||
assert_nil(ConfigVersion.active_config) | ||
end | ||
|
||
def test_reject_limited_admins_without_publish_permission | ||
config = { | ||
:website_backends => { | ||
@localhost_website.id => { :publish => "1" }, | ||
}, | ||
} | ||
|
||
unauthorized_localhost_admin = FactoryBot.create(:limited_admin, :groups => [FactoryBot.create(:localhost_root_admin_group, :backend_manage_permission)]) | ||
response = Typhoeus.post("https://127.0.0.1:9081/api-umbrella/v1/config/publish.json", http_options.deep_merge(admin_token(unauthorized_localhost_admin)).deep_merge({ | ||
:headers => { "Content-Type" => "application/x-www-form-urlencoded" }, | ||
:body => { :config => config }, | ||
})) | ||
|
||
assert_response_code(403, response) | ||
data = MultiJson.load(response.body) | ||
assert_equal(["errors"], data.keys) | ||
assert_nil(ConfigVersion.active_config) | ||
end | ||
|
||
def test_reject_limited_admins_without_root_url_permission | ||
config = { | ||
:website_backends => { | ||
@localhost_website.id => { :publish => "1" }, | ||
}, | ||
} | ||
|
||
localhost_admin = FactoryBot.create(:limited_admin, :groups => [FactoryBot.create(:google_admin_group, :backend_publish_permission)]) | ||
response = Typhoeus.post("https://127.0.0.1:9081/api-umbrella/v1/config/publish.json", http_options.deep_merge(admin_token(localhost_admin)).deep_merge({ | ||
:headers => { "Content-Type" => "application/x-www-form-urlencoded" }, | ||
:body => { :config => config }, | ||
})) | ||
|
||
assert_response_code(403, response) | ||
data = MultiJson.load(response.body) | ||
assert_equal(["errors"], data.keys) | ||
assert_nil(ConfigVersion.active_config) | ||
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
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