Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Testing Trailblazer applications usually involves the following tests.
All the up to date details on the available assertions and helpers is available at official documentation.
To use available assertions, add in your test _helper
the following modules:
include Trailblazer::Test::Assertions
include Trailblazer::Test::Operation::Assertions
If you are using Trailblazer v2.0 you need to add also:
require "trailblazer/test/deprecation/operation/assertions"
include Trailblazer::Test::Deprecation::Operation::Assertions # in your test class
Use assert_pass
to run an operation and assert it was successful, while checking if the attributes of the operation's model
are what you're expecting.
it { assert_pass Blog::Operation::Create, { params: { title: "Ruby Soho" } }, title: "Ruby Soho" }
To test an unsuccessful outcome of an operation, use assert_fail
. This is used for testing all kinds of validations. By passing insufficient or wrong data to the operation, it will fail and mark errors on the errors object.
it { assert_fail Blog::Operation::Update, { params: { band: nil } }, expected_errors: [:band] }
This will test that the operation fails due to a policy failure.
it { assert_policy_fail Blog::Operation::Delete, ctx({title: "Ruby Soho"}, current_user: not_allowed_user) }
Test attributes of an arbitrary object.
it { assert_exposes model, title: "Timebomb", band: "Rancid" }
There are several helpers to deal with operation tests and operations used as factories.
Add this in your _helper.rb
file to use all available helpers.
include Trailblazer::Test::Operation::Helper
Instead of manually invoking an operation, you can use the call
helper.
it do
result = call Blog::Operation::Create, params: {title: "Shipwreck", band: "Rancid"}
# use `result` object however you want
end
The factory
method calls the operation and raises an error should the operation have failed. If successful, it will do the exact same thing call
does.
it do
assert_raises do
factory Blog::Operation::Create, params: {title: "Shipwreck", band: "The Chats"}
end
end
This helper allows you to mock any step within a given or deeply nested activities. For example,
class Show < Trailblazer::Operation
step :load_user
...
end
To skip processing inside :load_user
and use a mock instead, use mock_step
.
it do
new_activity = mock_step(Show, id: :load_user) do |ctx|
ctx[:user] = Struct.new(:name).new('Mocky')
end
assert_pass new_activity, {}, {} do |ctx|
assert_equal ctx[:user].name, 'Mocky'
end
end
Add this line to your application's Gemfile:
gem 'trailblazer-test'
And then execute:
$ bundle
Or install it yourself as:
$ gem install trailblazer-test
FAQs
Unknown package
We found that trailblazer-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.