Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions gems/actionpack/7.2/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,23 @@ class BarController < ActionController::Base
class FooService
include ActionDispatch::Routing::RouteSet.new.url_helpers
end

# HTTP authentication returns the block value, or the rendered body when it requests credentials
class AuthController < ActionController::Base
http_basic_authenticate_with name: "dhh", password: "secret", except: :index

def show
authenticate_with_http_token { |token, options| token.length + options.size }&.succ
authenticate_or_request_with_http_token("Admin") { |token, _options| token.upcase }.downcase
request_http_token_authentication("Admin", "Denied").length

authenticate_with_http_basic { |name, password| "#{name}:#{password}" }&.length
authenticate_or_request_with_http_basic("Admin") { |name, _password| name.to_s }.length
request_http_basic_authentication.length
http_basic_authenticate_or_request_with(name: "dhh", password: "secret", realm: "Admin")

authenticate_with_http_digest("Admin") { |username| username == "dhh" ? "secret" : nil }
authenticate_or_request_with_http_digest { |username| username ? "secret" : nil }
request_http_digest_authentication("Admin", "Denied").length
end
end
4 changes: 4 additions & 0 deletions gems/actionpack/7.2/_test/test.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ end

class FooService
end

class AuthController < ActionController::Base
def show: () -> void
end
44 changes: 39 additions & 5 deletions gems/actionpack/7.2/actioncontroller.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ module ActionController
extend ::ActionController::HttpAuthentication::Token

module ControllerMethods
def authenticate_or_request_with_http_token: (?String realm, ?String? message) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> untyped
def authenticate_or_request_with_http_token: [T] (?String realm, ?String? message) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> (T | String)

def authenticate_with_http_token: () { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> boolish
def authenticate_with_http_token: [T] () { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> T?

def request_http_token_authentication: (?String realm, ?String? message) -> void
def request_http_token_authentication: (?String realm, ?String? message) -> String
end

def authenticate: (instance controller) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> boolish
def authenticate: [T] (instance controller) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> T?

def token_and_options: (ActionDispatch::Request request) -> [String, ActiveSupport::HashWithIndifferentAccess[untyped, untyped]]?

Expand All @@ -122,7 +122,41 @@ module ActionController

def encode_credentials: (String token, ?::Hash[untyped, untyped] options) -> ::String

def authentication_request: (instance controller, String realm, ?String? message) -> void
def authentication_request: (instance controller, String realm, ?String? message) -> String
end

module Basic
module ControllerMethods
module ClassMethods
def http_basic_authenticate_with: (name: String, password: String, ?realm: String?, **untyped options) -> void
end

def http_basic_authenticate_or_request_with: (name: String, password: String, ?realm: String?, ?message: String?) -> (true | String)

def authenticate_or_request_with_http_basic: [T] (?String? realm, ?String? message) { (String? name, String? password) -> T } -> (T | String)

def authenticate_with_http_basic: [T] () { (String? name, String? password) -> T } -> T?

def request_http_basic_authentication: (?String realm, ?String? message) -> String
end

def authenticate: [T] (ActionDispatch::Request request) { (String? name, String? password) -> T } -> T?

def authentication_request: (ActionController::Metal controller, String realm, String? message) -> String
end

module Digest
module ControllerMethods
def authenticate_or_request_with_http_digest: (?String realm, ?String? message) { (String? username) -> String? } -> (true | String)

def authenticate_with_http_digest: (?String realm) { (String? username) -> String? } -> bool?

def request_http_digest_authentication: (?String realm, ?String? message) -> String
end

def authenticate: (ActionDispatch::Request request, String realm) { (String? username) -> String? } -> bool?

def authentication_request: (ActionController::Metal controller, String realm, ?String? message) -> String
end
end
end
Expand Down
25 changes: 0 additions & 25 deletions gems/actionpack/7.2/actionpack-generated.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -1660,20 +1660,9 @@ module ActionController
extend ActiveSupport::Concern

module ClassMethods
def http_basic_authenticate_with: (password: untyped password, name: untyped name, ?realm: untyped? realm, **untyped options) -> untyped
end

def http_basic_authenticate_or_request_with: (password: untyped password, name: untyped name, ?message: untyped? message, ?realm: untyped? realm) -> untyped

def authenticate_or_request_with_http_basic: (?untyped? realm, ?untyped? message) { () -> untyped } -> untyped

def authenticate_with_http_basic: () { () -> untyped } -> untyped

def request_http_basic_authentication: (?::String realm, ?untyped? message) -> untyped
end

def authenticate: (untyped request) { () -> untyped } -> untyped

def has_basic_credentials?: (untyped request) -> untyped

def user_name_and_password: (untyped request) -> untyped
Expand All @@ -1685,8 +1674,6 @@ module ActionController
def auth_param: (untyped request) -> untyped

def encode_credentials: (untyped user_name, untyped password) -> ::String

def authentication_request: (untyped controller, untyped realm, untyped message) -> untyped
end

# Makes it dead easy to do HTTP \Digest authentication.
Expand Down Expand Up @@ -1735,18 +1722,8 @@ module ActionController
extend ::ActionController::HttpAuthentication::Digest

module ControllerMethods
def authenticate_or_request_with_http_digest: (?::String realm, ?untyped? message) { () -> untyped } -> untyped

# Authenticate with HTTP Digest, returns true or false
def authenticate_with_http_digest: (?::String realm) { () -> untyped } -> untyped

# Render output including the HTTP Digest authentication header
def request_http_digest_authentication: (?::String realm, ?untyped? message) -> untyped
end

# Returns false on a valid response, true otherwise
def authenticate: (untyped request, untyped realm) { () -> untyped } -> untyped

# Returns false unless the request credentials response value matches the expected value.
# First try the password as a ha1 digest password. If this fails, then try it as a plain
# text password.
Expand All @@ -1767,8 +1744,6 @@ module ActionController

def authentication_header: (untyped controller, untyped realm) -> untyped

def authentication_request: (untyped controller, untyped realm, ?untyped? message) -> untyped

def secret_token: (untyped request) -> untyped

# Uses an MD5 digest based on time to generate a value to be used only once.
Expand Down
20 changes: 20 additions & 0 deletions gems/actionpack/8.1/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,23 @@ class FooIntegrationTest < ActionDispatch::IntegrationTest

ActionDispatch::Request.parameter_parsers = {}
ActionDispatch::Callbacks.define_callbacks(:notify)

# HTTP authentication returns the block value, or the rendered body when it requests credentials
class AuthController < ActionController::Base
http_basic_authenticate_with name: "dhh", password: "secret", except: :index

def show
authenticate_with_http_token { |token, options| token.length + options.size }&.succ
authenticate_or_request_with_http_token("Admin") { |token, _options| token.upcase }.downcase
request_http_token_authentication("Admin", "Denied").length

authenticate_with_http_basic { |name, password| "#{name}:#{password}" }&.length
authenticate_or_request_with_http_basic("Admin") { |name, _password| name.to_s }.length
request_http_basic_authentication.length
http_basic_authenticate_or_request_with(name: "dhh", password: "secret", realm: "Admin")

authenticate_with_http_digest("Admin") { |username| username == "dhh" ? "secret" : nil }
authenticate_or_request_with_http_digest { |username| username ? "secret" : nil }
request_http_digest_authentication("Admin", "Denied").length
end
end
4 changes: 4 additions & 0 deletions gems/actionpack/8.1/_test/test.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ end

class FooIntegrationTest < ActionDispatch::IntegrationTest
end

class AuthController < ActionController::Base
def show: () -> void
end
44 changes: 39 additions & 5 deletions gems/actionpack/8.1/actioncontroller.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ module ActionController
extend ::ActionController::HttpAuthentication::Token

module ControllerMethods
def authenticate_or_request_with_http_token: (?String realm, ?String? message) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> untyped
def authenticate_or_request_with_http_token: [T] (?String realm, ?String? message) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> (T | String)

def authenticate_with_http_token: () { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> boolish
def authenticate_with_http_token: [T] () { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> T?

def request_http_token_authentication: (?String realm, ?String? message) -> void
def request_http_token_authentication: (?String realm, ?String? message) -> String
end

def authenticate: (instance controller) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> boolish } -> boolish
def authenticate: [T] (instance controller) { (String token, ActiveSupport::HashWithIndifferentAccess[untyped, untyped] options) -> T } -> T?

def token_and_options: (ActionDispatch::Request request) -> [String, ActiveSupport::HashWithIndifferentAccess[untyped, untyped]]?

Expand All @@ -148,7 +148,41 @@ module ActionController

def encode_credentials: (String token, ?::Hash[untyped, untyped] options) -> ::String

def authentication_request: (instance controller, String realm, ?String? message) -> void
def authentication_request: (instance controller, String realm, ?String? message) -> String
end

module Basic
module ControllerMethods
module ClassMethods
def http_basic_authenticate_with: (name: String, password: String, ?realm: String?, **untyped options) -> void
end

def http_basic_authenticate_or_request_with: (name: String, password: String, ?realm: String?, ?message: String?) -> (true | String)

def authenticate_or_request_with_http_basic: [T] (?String? realm, ?String? message) { (String? name, String? password) -> T } -> (T | String)

def authenticate_with_http_basic: [T] () { (String? name, String? password) -> T } -> T?

def request_http_basic_authentication: (?String realm, ?String? message) -> String
end

def authenticate: [T] (ActionDispatch::Request request) { (String? name, String? password) -> T } -> T?

def authentication_request: (ActionController::Metal controller, String realm, String? message) -> String
end

module Digest
module ControllerMethods
def authenticate_or_request_with_http_digest: (?String realm, ?String? message) { (String? username) -> String? } -> (true | String)

def authenticate_with_http_digest: (?String realm) { (String? username) -> String? } -> bool?

def request_http_digest_authentication: (?String realm, ?String? message) -> String
end

def authenticate: (ActionDispatch::Request request, String realm) { (String? username) -> String? } -> bool?

def authentication_request: (ActionController::Metal controller, String realm, ?String? message) -> String
end
end
end
Expand Down
34 changes: 0 additions & 34 deletions gems/actionpack/8.1/actionpack-generated.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2189,23 +2189,9 @@ module ActionController
extend ::ActiveSupport::Concern

module ClassMethods
# Enables HTTP Basic authentication.
#
# See ActionController::HttpAuthentication::Basic for example usage.
def http_basic_authenticate_with: (name: untyped, password: untyped, ?realm: untyped?, **untyped options) -> untyped
end

def http_basic_authenticate_or_request_with: (name: untyped, password: untyped, ?realm: untyped?, ?message: untyped?) -> untyped

def authenticate_or_request_with_http_basic: (?untyped? realm, ?untyped? message) { (?) -> untyped } -> untyped

def authenticate_with_http_basic: () { (?) -> untyped } -> untyped

def request_http_basic_authentication: (?::String realm, ?untyped? message) -> untyped
end

def authenticate: (untyped request) { (?) -> untyped } -> (untyped | nil)

def has_basic_credentials?: (untyped request) -> untyped

def user_name_and_password: (untyped request) -> untyped
Expand All @@ -2217,8 +2203,6 @@ module ActionController
def auth_param: (untyped request) -> untyped

def encode_credentials: (untyped user_name, untyped password) -> ::String

def authentication_request: (untyped controller, untyped realm, untyped message) -> untyped
end

# # HTTP Digest authentication
Expand Down Expand Up @@ -2268,24 +2252,8 @@ module ActionController
extend ::ActionController::HttpAuthentication::Digest

module ControllerMethods
# Authenticate using an HTTP Digest, or otherwise render an HTTP header
# requesting the client to send a Digest.
#
# See ActionController::HttpAuthentication::Digest for example usage.
def authenticate_or_request_with_http_digest: (?::String realm, ?untyped? message) { (?) -> untyped } -> untyped

# Authenticate using an HTTP Digest. Returns true if authentication is
# successful, false otherwise.
def authenticate_with_http_digest: (?::String realm) { (?) -> untyped } -> untyped

# Render an HTTP header requesting the client to send a Digest for
# authentication.
def request_http_digest_authentication: (?::String realm, ?untyped? message) -> untyped
end

# Returns true on a valid response, false otherwise.
def authenticate: (untyped request, untyped realm) { (?) -> untyped } -> untyped

# Returns false unless the request credentials response value matches the
# expected value. First try the password as a ha1 digest password. If this
# fails, then try it as a plain text password.
Expand All @@ -2307,8 +2275,6 @@ module ActionController

def authentication_header: (untyped controller, untyped realm) -> untyped

def authentication_request: (untyped controller, untyped realm, ?untyped? message) -> untyped

def secret_token: (untyped request) -> untyped

# Uses an MD5 digest based on time to generate a value to be used only once.
Expand Down
Loading