Skip to content

Commit

Permalink
Fix Push Expiration bug with Public Gateway (#2546)
Browse files Browse the repository at this point in the history
* Fix Push Expiration bug with Public Gateway

* Test: Fix request path
  • Loading branch information
pglombardo committed Sep 23, 2024
1 parent a1cf2f5 commit 2de5489
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/file_pushes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def destroy

if @push.expired
respond_to do |format|
format.html { redirect_to :root, notice: _("That push is already expired.") }
format.html { redirect_to @push }
format.json { render json: {error: _("That push is already expired.")}, status: :unprocessable_entity }
end
return
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def destroy

if @push.expired
respond_to do |format|
format.html { redirect_to :root, notice: _("That push is already expired.") }
format.html { redirect_to @push }
format.json { render json: {error: _("That push is already expired.")}, status: :unprocessable_entity }
end
return
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/urls_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def destroy

if @push.expired
respond_to do |format|
format.html { redirect_to :root, notice: _("That push is already expired.") }
format.html { redirect_to @push }
format.json { render json: {error: _("That push is already expired.")}, status: :unprocessable_entity }
end
return
Expand Down
51 changes: 48 additions & 3 deletions test/integration/password/password_deletion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_anonymous_password_deletion
assert_response :success
assert_select "h2", "Your push has been created."

# view the password
# view the push
get request.url.sub("/preview", "")
assert_response :success

Expand All @@ -23,11 +23,56 @@ def test_anonymous_password_deletion
assert(pre)
assert(pre.first.content.include?("testpw"))

# Delete the passworda
# Expire the push
delete request.url
assert_response :redirect

# Get redirected to the password that is now expired
# Get redirected to the push that is now expired
follow_redirect!
assert_response :success
assert response.body.include?("We apologize but this secret link has expired.")

# Retrieve the preliminary page. It should show expired too.
get preliminary_password_path(Password.last)
assert_response :success
assert response.body.include?("We apologize but this secret link has expired.")
end

def test_delete_already_expired_goes_to_expired_path
assert Settings.pw.enable_deletable_pushes == true
# create
post passwords_path, params: {password: {payload: "testpw", deletable_by_viewer: "on", expire_after_views: 1}}
assert_response :redirect

# preview
follow_redirect!
assert_response :success
assert_select "h2", "Your push has been created."

push_url = request.url.sub("/preview", "")

# view the push
get push_url
assert_response :success

# Assert that the right password is in the page
pre = css_select "pre"
assert(pre)
assert(pre.first.content.include?("testpw"))

# view the push again should give expired page
get push_url
assert_response :success

expired_p = css_select "p.text-center"
assert(expired_p)
assert(expired_p.first.content.include?("We apologize but this secret link has expired."))

# Delete the already expired push
delete push_url
assert_response :redirect

# Get redirected to the push that is now expired
follow_redirect!
assert_response :success
assert response.body.include?("We apologize but this secret link has expired.")
Expand Down

0 comments on commit 2de5489

Please sign in to comment.