Skip to content

Commit

Permalink
Don't crash when a GraphQL-requested workspace with the random argu…
Browse files Browse the repository at this point in the history
…ment doesn't exist. (#2213)

Reported by Sentry.

Fixes: CV2-6151.
  • Loading branch information
caiosba authored Feb 11, 2025
1 parent 2393988 commit f7ca752
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/graph/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ def me

def team(id: nil, slug: nil, random: nil)
tid = id.to_i
team = nil
unless slug.blank?
team = Team.where(slug: slug).first
tid = team.id unless team.nil?
end
team.reload if random
team.reload if team && random
tid = Team.current&.id || User.current&.teams&.first&.id if tid === 0
GraphqlCrudOperations.load_if_can(Team, tid.to_i, context)
end
Expand Down
20 changes: 20 additions & 0 deletions test/controllers/graphql_controller_11_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,24 @@ def teardown
assert_equal pm1.created_at.to_i, response['media_cluster_origin_timestamp']
assert_equal CheckMediaClusterOrigins::OriginCodes::USER_ADDED, response['media_cluster_origin']
end

test "should not crash if workspace doesn't exist" do
t = create_team
u = create_user
create_team_user team: t, user: u, role: 'admin'
authenticate_with_user(u)
t.delete

query = <<~GRAPHQL
query {
team(slug: "#{t.slug}", random: "123456") {
name
}
}
GRAPHQL

post :create, params: { query: query, team: t.slug }
assert_response :success
assert_match /ActiveRecord::RecordNotFound/, @response.body
end
end

0 comments on commit f7ca752

Please sign in to comment.