应用程序安全测试:用户、角色与访问控制
1. 添加用户和角色测试
在安装了 Devise 之后,我们可以通过测试来发现应用程序中的安全问题,其中最基础的安全问题就是用户登录。由于应用涉及特定的私有项目,只有登录用户才能访问,这是可测试的逻辑。
下面是一个针对项目索引页面的集成测试示例:
# security/01/spec/system/user_and_role_spec.rb
require "rails_helper"
RSpec.describe "with users and roles" do
def log_in_as(user)
visit new_user_session_path
fill_in("user_email", with: user.email)
fill_in("user_password", with: user.password)
click_button("Log in")
end
let(:user) { User.create(email: "test@example.com", password: "password") }
it "allows a logged-in user to view the project index page" do
log_in_as(user)
visit(projects_path)
expect(current_path).to eq(projects_path)
end
it "does not allow a user to see the pro
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



