-
Notifications
You must be signed in to change notification settings - Fork 21.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to prevent access to a database
- Loading branch information
1 parent
1b226d5
commit c438333
Showing
22 changed files
with
300 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cases/helper" | ||
require "support/connection_helper" | ||
|
||
module ActiveRecord | ||
class AdapterPreventAccessTest < ActiveRecord::TestCase | ||
def setup | ||
@connection = ActiveRecord::Base.lease_connection | ||
end | ||
|
||
def test_preventing_access_predicate | ||
assert_not_predicate @connection, :preventing_access? | ||
|
||
ActiveRecord::Base.while_preventing_access do | ||
assert_predicate @connection, :preventing_access? | ||
end | ||
|
||
assert_not_predicate @connection, :preventing_access? | ||
end | ||
|
||
def test_errors_when_query_is_called_while_preventing_access | ||
@connection.select_all("SELECT count(*) FROM subscribers") | ||
|
||
ActiveRecord::Base.while_preventing_access do | ||
assert_raises(ActiveRecord::PreventedAccessError) do | ||
@connection.select_all("SELECT count(*) FROM subscribers") | ||
end | ||
end | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
activerecord/test/cases/adapters/abstract_mysql_adapter/adapter_prevent_access_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cases/helper" | ||
require "support/ddl_helper" | ||
|
||
class AdapterPreventAccessTest < ActiveRecord::AbstractMysqlTestCase | ||
include DdlHelper | ||
|
||
def setup | ||
@conn = ActiveRecord::Base.lease_connection | ||
end | ||
|
||
def test_error_when_a_query_is_called_while_preventing_access | ||
@conn.execute("INSERT INTO `engines` (`car_id`) VALUES ('138853948594')") | ||
|
||
ActiveRecord::Base.while_preventing_access do | ||
assert_raises(ActiveRecord::PreventedAccessError) do | ||
@conn.execute("SELECT `engines`.* FROM `engines` WHERE `engines`.`car_id` = '138853948594'") | ||
end | ||
end | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
activerecord/test/cases/adapters/postgresql/postgresql_adapter_prevent_access_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cases/helper" | ||
require "support/ddl_helper" | ||
require "support/connection_helper" | ||
|
||
module ActiveRecord | ||
module ConnectionAdapters | ||
class PostgreSQLAdapterPreventWritesTest < ActiveRecord::PostgreSQLTestCase | ||
include DdlHelper | ||
include ConnectionHelper | ||
|
||
def setup | ||
@connection = ActiveRecord::Base.lease_connection | ||
end | ||
|
||
def test_error_when_a_query_is_called_while_preventing_access | ||
@conn.execute("INSERT INTO `engines` (`car_id`) VALUES ('138853948594')") | ||
|
||
ActiveRecord::Base.while_preventing_access do | ||
assert_raises(ActiveRecord::PreventedAccessError) do | ||
@conn.execute("SELECT `engines`.* FROM `engines` WHERE `engines`.`car_id` = '138853948594'") | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.