Skip to content

Commit 57d0e72

Browse files
dadachiclaude
andcommitted
Make 'source' header optional on shopkeeper sign-in
Reverts the earlier "require source header" form. Anti-mass-signup is now handled at the right layer by the sign-up rate_limit introduced in PR #50, so the sign-in header has no security job left. current_platform is informational metadata; rejecting sign-ins on missing metadata is too aggressive — it breaks non-mobile callers (curl, CI, integration tools, future web client) without a real benefit. Skip the current_platform update when the header is blank: the existing stored value is preserved (instead of being nuked to nil by the original buggy code path). Drop the missing_source locale key. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0de6fe4 commit 57d0e72

3 files changed

Lines changed: 6 additions & 10 deletions

File tree

app/controllers/shopkeeper_auth/sessions_controller.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
class ShopkeeperAuth::SessionsController < DeviseTokenAuth::SessionsController
22
def create
3-
source = request.headers["source"]
4-
if source.blank?
5-
return render json: {code: 401, error_message: I18n.t("devise_token_auth.sessions.missing_source")}, status: :unauthorized
6-
end
7-
83
super
94
return if @resource.blank?
105

6+
source = request.headers["source"]
7+
return if source.blank?
8+
119
@resource.current_platform = source
1210
@resource.save!(validate: false)
1311
end

config/locales/en.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ en:
8888
not_confirmed: "A confirmation email was sent to your account at '%{email}'. You must follow the instructions in the email before your account can be activated."
8989
bad_credentials: "Invalid email or password. Please try again."
9090
user_not_found: "User was not found or was not signed in."
91-
missing_source: "Missing 'source' header."
9291
passwords:
9392
missing_email: "You must provide an email address."
9493
missing_redirect_url: "Missing redirect URL."

test/controllers/shopkeeper_auth/sessions_controller_test.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class ShopkeeperAuth::SessionsControllerTest < ActionDispatch::IntegrationTest
44
test "returns unauthorized if shopkeeper not valid" do
5-
post shopkeeper_session_url, headers: {source: "ios"}
5+
post shopkeeper_session_url
66
assert_response :unauthorized
77
assert response.parsed_body["error_message"]
88
assert_equal I18n.t("devise_token_auth.sessions.bad_credentials"), response.parsed_body["error_message"]
@@ -42,16 +42,15 @@ class ShopkeeperAuth::SessionsControllerTest < ActionDispatch::IntegrationTest
4242
assert_equal "android", shopkeeper.reload.current_platform
4343
end
4444

45-
test "sign-in without source header is rejected with 401" do
45+
test "successful sign-in without source header preserves the existing current_platform" do
4646
shopkeeper = shopkeepers(:one)
4747
shopkeeper.create_default_account
4848
shopkeeper.update_column(:current_platform, "ios")
4949

5050
post shopkeeper_session_url,
5151
params: {email: shopkeeper.email, password: "password"}
5252

53-
assert_response :unauthorized
54-
assert_equal I18n.t("devise_token_auth.sessions.missing_source"), response.parsed_body["error_message"]
53+
assert_response :success
5554
assert_equal "ios", shopkeeper.reload.current_platform
5655
end
5756
end

0 commit comments

Comments
 (0)