Skip to content

Commit

Permalink
Add missing alias methods for boolean settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ellmetha committed Sep 24, 2024
1 parent f7385e7 commit f9296fb
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 3 deletions.
19 changes: 19 additions & 0 deletions spec/marten/conf/global_settings/assets_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ describe Marten::Conf::GlobalSettings::Assets do
end
end

describe "#app_dirs?" do
it "returns true by default" do
assets_conf = Marten::Conf::GlobalSettings::Assets.new
assets_conf.app_dirs?.should be_true
end

it "returns true if configured accordingly" do
assets_conf = Marten::Conf::GlobalSettings::Assets.new
assets_conf.app_dirs = true
assets_conf.app_dirs?.should be_true
end

it "returns false if configured accordingly" do
assets_conf = Marten::Conf::GlobalSettings::Assets.new
assets_conf.app_dirs = false
assets_conf.app_dirs?.should be_false
end
end

describe "#app_dirs=" do
it "allows to change the app_dirs confiuration as expected" do
assets_conf = Marten::Conf::GlobalSettings::Assets.new
Expand Down
52 changes: 52 additions & 0 deletions spec/marten/conf/global_settings/csrf_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ describe Marten::Conf::GlobalSettings::CSRF do
end
end

describe "#cookie_http_only?" do
it "returns false by default" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
csrf_conf.cookie_http_only?.should be_false
end

it "returns the configured value if applicable" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
csrf_conf.cookie_http_only = true
csrf_conf.cookie_http_only?.should be_true
end
end

describe "#cookie_http_only=" do
it "allows to configure that client-side JS scripts should not have access to the CSRF cookie" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
Expand Down Expand Up @@ -125,6 +138,19 @@ describe Marten::Conf::GlobalSettings::CSRF do
end
end

describe "#cookie_secure?" do
it "returns false by default" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
csrf_conf.cookie_secure?.should be_false
end

it "returns the configured value if applicable" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
csrf_conf.cookie_secure = true
csrf_conf.cookie_secure?.should be_true
end
end

describe "#cookie_secure=" do
it "allows to configure whether a secure cookie should be used" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
Expand All @@ -146,6 +172,19 @@ describe Marten::Conf::GlobalSettings::CSRF do
end
end

describe "#protection_enabled?" do
it "returns true by default" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
csrf_conf.protection_enabled?.should be_true
end

it "returns the configured value if applicable" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
csrf_conf.protection_enabled = false
csrf_conf.protection_enabled?.should be_false
end
end

describe "#protection_enabled=" do
it "allows to disable the CSRF protection" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
Expand Down Expand Up @@ -215,6 +254,19 @@ describe Marten::Conf::GlobalSettings::CSRF do
end
end

describe "#use_session?" do
it "returns false by default" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
csrf_conf.use_session?.should be_false
end

it "returns the configured value if applicable" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
csrf_conf.use_session = true
csrf_conf.use_session?.should be_true
end
end

describe "#use_session=" do
it "allows to store the CSRF token inside a session" do
csrf_conf = Marten::Conf::GlobalSettings::CSRF.new
Expand Down
26 changes: 26 additions & 0 deletions spec/marten/conf/global_settings/sessions_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ describe Marten::Conf::GlobalSettings::Sessions do
end
end

describe "#cookie_http_only?" do
it "returns false by default" do
sessions_conf = Marten::Conf::GlobalSettings::Sessions.new
sessions_conf.cookie_http_only?.should be_false
end

it "returns the configured value if applicable" do
sessions_conf = Marten::Conf::GlobalSettings::Sessions.new
sessions_conf.cookie_http_only = true
sessions_conf.cookie_http_only?.should be_true
end
end

describe "#cookie_http_only=" do
it "allows to configure that client-side JS scripts should not have access to the session cookie" do
sessions_conf = Marten::Conf::GlobalSettings::Sessions.new
Expand Down Expand Up @@ -125,6 +138,19 @@ describe Marten::Conf::GlobalSettings::Sessions do
end
end

describe "#cookie_secure?" do
it "returns false by default" do
sessions_conf = Marten::Conf::GlobalSettings::Sessions.new
sessions_conf.cookie_secure?.should be_false
end

it "returns the configured value if applicable" do
sessions_conf = Marten::Conf::GlobalSettings::Sessions.new
sessions_conf.cookie_secure = true
sessions_conf.cookie_secure?.should be_true
end
end

describe "#cookie_secure=" do
it "allows to configure whether a secure cookie should be used" do
sessions_conf = Marten::Conf::GlobalSettings::Sessions.new
Expand Down
26 changes: 26 additions & 0 deletions spec/marten/conf/global_settings/strict_transport_security_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ describe Marten::Conf::GlobalSettings::StrictTransportSecurity do
end
end

describe "#include_sub_domains?" do
it "returns false by default" do
sts_config = Marten::Conf::GlobalSettings::StrictTransportSecurity.new
sts_config.include_sub_domains?.should be_false
end

it "returns the customized value if applicable" do
sts_config = Marten::Conf::GlobalSettings::StrictTransportSecurity.new
sts_config.include_sub_domains = true
sts_config.include_sub_domains?.should be_true
end
end

describe "#include_sub_domains=" do
it "allows to specify a custom setting value as expected" do
sts_config = Marten::Conf::GlobalSettings::StrictTransportSecurity.new
Expand Down Expand Up @@ -56,6 +69,19 @@ describe Marten::Conf::GlobalSettings::StrictTransportSecurity do
end
end

describe "#preload?" do
it "returns false by default" do
sts_config = Marten::Conf::GlobalSettings::StrictTransportSecurity.new
sts_config.preload?.should be_false
end

it "returns the customized value if applicable" do
sts_config = Marten::Conf::GlobalSettings::StrictTransportSecurity.new
sts_config.preload = true
sts_config.preload?.should be_true
end
end

describe "#preload=" do
it "allows to specify a custom setting value as expected" do
sts_config = Marten::Conf::GlobalSettings::StrictTransportSecurity.new
Expand Down
38 changes: 38 additions & 0 deletions spec/marten/conf/global_settings/templates_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ describe Marten::Conf::GlobalSettings::Templates do
end
end

describe "#app_dirs?" do
it "returns true by default" do
templates_conf = Marten::Conf::GlobalSettings::Templates.new
templates_conf.app_dirs?.should be_true
end

it "returns true if configured accordingly" do
templates_conf = Marten::Conf::GlobalSettings::Templates.new
templates_conf.app_dirs = true
templates_conf.app_dirs?.should be_true
end

it "returns false if configured accordingly" do
templates_conf = Marten::Conf::GlobalSettings::Templates.new
templates_conf.app_dirs = false
templates_conf.app_dirs?.should be_false
end
end

describe "#app_dirs=" do
it "allows to change the app_dirs confiuration as expected" do
templates_conf = Marten::Conf::GlobalSettings::Templates.new
Expand Down Expand Up @@ -51,6 +70,25 @@ describe Marten::Conf::GlobalSettings::Templates do
end
end

describe "#cached?" do
it "returns false by default" do
templates_conf = Marten::Conf::GlobalSettings::Templates.new
templates_conf.cached?.should be_false
end

it "returns true if configured accordingly" do
templates_conf = Marten::Conf::GlobalSettings::Templates.new
templates_conf.cached = true
templates_conf.cached?.should be_true
end

it "returns false if configured accordingly" do
templates_conf = Marten::Conf::GlobalSettings::Templates.new
templates_conf.cached = false
templates_conf.cached?.should be_false
end
end

describe "#cached=" do
it "allows to change the cached configuration as expected" do
templates_conf = Marten::Conf::GlobalSettings::Templates.new
Expand Down
52 changes: 52 additions & 0 deletions spec/marten/conf/global_settings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,19 @@ describe Marten::Conf::GlobalSettings do
end
end

describe "#port_reuse?" do
it "returns true by default" do
global_settings = Marten::Conf::GlobalSettings.new
global_settings.port_reuse?.should be_true
end

it "returns the specific port reuse configuration if explicitely set" do
global_settings = Marten::Conf::GlobalSettings.new
global_settings.port_reuse = false
global_settings.port_reuse?.should be_false
end
end

describe "#port_reuse=" do
it "allows to configure whether the port_reuse boolean configuration option" do
global_settings = Marten::Conf::GlobalSettings.new
Expand Down Expand Up @@ -601,6 +614,19 @@ describe Marten::Conf::GlobalSettings do
end
end

describe "#use_x_forwarded_host?" do
it "returns false by default" do
global_settings = Marten::Conf::GlobalSettings.new
global_settings.use_x_forwarded_host?.should be_false
end

it "returns the configured boolean value if explicitely set" do
global_settings = Marten::Conf::GlobalSettings.new
global_settings.use_x_forwarded_host = true
global_settings.use_x_forwarded_host?.should be_true
end
end

describe "#use_x_forwarded_host=" do
it "allows to configure whether the X-Forwarded-Host header should be used" do
global_settings = Marten::Conf::GlobalSettings.new
Expand All @@ -622,6 +648,19 @@ describe Marten::Conf::GlobalSettings do
end
end

describe "#use_x_forwarded_port?" do
it "returns false by default" do
global_settings = Marten::Conf::GlobalSettings.new
global_settings.use_x_forwarded_port?.should be_false
end

it "returns the configured boolean value if explicitely set" do
global_settings = Marten::Conf::GlobalSettings.new
global_settings.use_x_forwarded_port = true
global_settings.use_x_forwarded_port?.should be_true
end
end

describe "#use_x_forwarded_port=" do
it "allows to configure whether the X-Forwarded-Port header should be used" do
global_settings = Marten::Conf::GlobalSettings.new
Expand All @@ -643,6 +682,19 @@ describe Marten::Conf::GlobalSettings do
end
end

describe "#use_x_forwarded_proto?" do
it "returns false by default" do
global_settings = Marten::Conf::GlobalSettings.new
global_settings.use_x_forwarded_proto?.should be_false
end

it "returns the configured boolean value if explicitely set" do
global_settings = Marten::Conf::GlobalSettings.new
global_settings.use_x_forwarded_proto = true
global_settings.use_x_forwarded_proto?.should be_true
end
end

describe "#use_x_forwarded_proto=" do
it "allows to configure whether the X-Forwarded-Proto header should be used" do
global_settings = Marten::Conf::GlobalSettings.new
Expand Down
12 changes: 12 additions & 0 deletions src/marten/conf/global_settings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ module Marten
# Returns a boolean indicating whether multiple processes can bind to the same HTTP server port.
getter port_reuse

# :ditto:
getter? port_reuse

# Returns the default value to use for the Referrer-Policy header.
#
# The value of this setting will be used by the `Marten::Middleware::ReferrerPolicy` middleware when inserting the
Expand All @@ -84,12 +87,21 @@ module Marten
# Returns a boolean indicating whether the X-Forwarded-Host header is used to look for the host.
getter use_x_forwarded_host

# :ditto:
getter? use_x_forwarded_host

# Returns a boolean indicating if the X-Forwarded-Port header is used to determine the port of a request.
getter use_x_forwarded_port

# :ditto:
getter? use_x_forwarded_port

# Returns a boolean indicating if the X-Forwarded-Proto header is used to determine whether a request is secure.
getter use_x_forwarded_proto

# :ditto:
getter? use_x_forwarded_proto

# Returns the value to use for the X-Frame-Options header when the associated middleware is used.
#
# The value of this setting will be used by the `Marten::Middleware::XFrameOptions` middleware when inserting the
Expand Down
3 changes: 3 additions & 0 deletions src/marten/conf/global_settings/assets.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module Marten
# Returns a boolean indicating whether assets should be looked for inside installed applications.
getter app_dirs

# :ditto:
getter? app_dirs

# Returns an array of directories where assets should be looked for.
#
# The order of these directories is important as it defines the order in which assets are searched for.
Expand Down
12 changes: 12 additions & 0 deletions src/marten/conf/global_settings/csrf.cr
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ module Marten
# Returns a boolean indicating whether client-side scripts should have access to the CSRF token cookie.
getter cookie_http_only

# :ditto:
getter? cookie_http_only

# Returns the max age (in seconds) of the CSRF cookie.
#
# By default, CSRF cookie max age is set to `31556952` (approximatively one year).
Expand All @@ -37,12 +40,21 @@ module Marten
# Returns a boolean indicating whether to use a secure cookie for the CSRF cookie.
getter cookie_secure

# :ditto:
getter? cookie_secure

# Returns a boolean indicating if CSRF protection is enabled globally (defaults to `true`).
getter protection_enabled

# :ditto:
getter? protection_enabled

# Returns a boolean indicating if the CSRF token is stored inside the session.
getter use_session

# :ditto:
getter? use_session

# Returns the array of CSRF-trusted origins.
getter trusted_origins

Expand Down
Loading

0 comments on commit f9296fb

Please sign in to comment.