Skip to content

Commit

Permalink
Allow registration of OAuth 1.0 applications to be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Jan 31, 2024
1 parent 3ab9da6 commit 31659be
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/controllers/oauth_clients_controller.rb
Expand Up @@ -19,7 +19,12 @@ def show
end

def new
@client_application = ClientApplication.new
if Settings.oauth_10_registration
@client_application = ClientApplication.new
else
flash[:error] = t ".disabled"
redirect_to :action => "index"
end
end

def edit
Expand Down
2 changes: 2 additions & 0 deletions app/views/oauth_clients/index.html.erb
Expand Up @@ -42,4 +42,6 @@
<% end %>
</ul>
<% end %>
<% if Settings.oauth_10_registration -%>
<%= link_to t(".register_new"), { :action => :new }, :class => "btn btn-outline-primary" %>
<% end -%>
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -2602,6 +2602,7 @@ en:
oauth_clients:
new:
title: "Register a new application"
disabled: "Registration of OAuth 1 applications has been disabled"
edit:
title: "Edit your application"
show:
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Expand Up @@ -97,6 +97,7 @@ attachments_dir: ":rails_root/public/attachments"
basic_auth_support: true
# Enable legacy OAuth 1.0 support
oauth_10_support: true
oauth_10_registration: true
# URL of Nominatim instance to use for geocoding
nominatim_url: "https://nominatim.openstreetmap.org/"
# Default editor
Expand Down
16 changes: 16 additions & 0 deletions test/controllers/oauth_clients_controller_test.rb
Expand Up @@ -74,6 +74,22 @@ def test_new
end
end

def test_new_disabled
user = create(:user)

with_settings(:oauth_10_registration => false) do
get new_oauth_client_path(:display_name => user.display_name)
assert_response :redirect
assert_redirected_to login_path(:referer => new_oauth_client_path(:display_name => user.display_name))

session_for(user)

get new_oauth_client_path(:display_name => user.display_name)
assert_response :redirect
assert_redirected_to oauth_clients_path(:display_name => user.display_name)
end
end

def test_create
user = create(:user)

Expand Down
10 changes: 10 additions & 0 deletions test/test_helper.rb
Expand Up @@ -374,6 +374,16 @@ def add_tags_to_xml_node(el, tags)
end
end

def with_settings(settings)
saved_settings = Settings.to_hash.slice(*settings.keys)

Settings.merge!(settings)

yield
ensure
Settings.merge!(saved_settings)
end

def with_user_account_deletion_delay(value)
freeze_time
default_value = Settings.user_account_deletion_delay
Expand Down

0 comments on commit 31659be

Please sign in to comment.