Simplify creation of bearer authorization headers

Uses the new features added to the bearer_authorization_header while
dropping basic authentication support to simplify the creation of bearer
authorization headers for API tests.
This commit is contained in:
Tom Hughes 2024-09-03 18:54:05 +01:00
parent 2af5094742
commit 4d221fd7a6
8 changed files with 72 additions and 152 deletions

View file

@ -303,11 +303,11 @@ module Api
# But writing oauth tests is hard, and so it's easier to put in a controller test.)
def test_api_write_and_terms_agreed_via_token
user = create(:user, :terms_agreed => nil)
token = create(:oauth_access_token, :resource_owner_id => user.id, :scopes => %w[write_api])
auth_header = bearer_authorization_header(user, :scopes => %w[write_api])
changeset = create(:changeset, :closed)
assert_difference "ChangesetComment.count", 0 do
post changeset_comment_path(changeset), :params => { :text => "This is a comment" }, :headers => bearer_authorization_header(token.token)
post changeset_comment_path(changeset), :params => { :text => "This is a comment" }, :headers => auth_header
end
assert_response :forbidden
@ -316,7 +316,7 @@ module Api
user.save!
assert_difference "ChangesetComment.count", 1 do
post changeset_comment_path(changeset), :params => { :text => "This is a comment" }, :headers => bearer_authorization_header(token.token)
post changeset_comment_path(changeset), :params => { :text => "This is a comment" }, :headers => auth_header
end
assert_response :success
end