Skip to content

Commit 88307fc

Browse files
committed
Fixed rails integration tests and missing random logs
1 parent ea0aa72 commit 88307fc

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Taskfile.rails.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ tasks:
99
desc: Run Rails integration tests (override with RAILS_VERSION=...)
1010
cmds:
1111
- cmd: RAILS_VERSION={{.RAILS_VERSION}} ./scripts/rails_tests.sh
12-
dir: .
12+
13+
test:force:
14+
desc: Run Rails integration tests with force recreation of test app (override with RAILS_VERSION=...)
15+
cmds:
16+
- cmd: RAILS_VERSION={{.RAILS_VERSION}} FORCE_RECREATE=true ./scripts/rails_tests.sh
1317

1418
test:matrix:
1519
desc: Run Rails integration tests for supported versions (7.1.5 and 8.0.1)

docs/lib/log-generation/sample-data.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ export const SampleByLogField: Readonly<Record<LogField, (gen: RandomGen) => unk
198198
[LogField.View]: (gen: RandomGen) => gen.randomFloat(0, 200),
199199
[LogField.Params]: (_gen: RandomGen) => ({}),
200200
[LogField.BlockedHosts]: (_gen: RandomGen) => ['malicious.example.com'],
201+
[LogField.AllowedHosts]: (_gen: RandomGen) => ['example.com', 'trusted.com'],
202+
[LogField.AllowIpHosts]: (_gen: RandomGen) => false,
201203
[LogField.ClientIp]: SampleHelpers.ip,
202204
[LogField.XForwardedFor]: (_gen: RandomGen) => '203.0.113.1, 70.41.3.18',
203205
[LogField.To]: SampleHelpers.emailArray,

rails_test_app/create_app.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,23 @@ def copy_template(file, target_path = nil)
331331
content = File.read(test_env_path)
332332
# Remove previous blanket clearing if present
333333
content.gsub!(/^\s*config\.hosts\.clear\s*\n/, "")
334+
# Remove old appending style if present
335+
content.gsub!(/^\s*# Allow test hostnames for integration tests\s*\n/, "")
336+
content.gsub!(/^\s*config\.hosts << "www\.example\.com"\s*\n/, "")
337+
content.gsub!(/^\s*config\.hosts << "127\.0\.0\.1"\s*\n/, "")
338+
content.gsub!(/^\s*config\.hosts << "localhost"\s*\n/, "")
339+
content.gsub!(/^\s*config\.hosts << \/\.\*\\z\/\s*\n/, "")
340+
334341
insert = <<~RUBY
335-
# Allow test hostnames for integration tests
336-
config.hosts << "www.example.com"
337-
config.hosts << "127.0.0.1"
338-
config.hosts << "localhost"
339-
config.hosts << /.*\z/
342+
# Host authorization for tests - allow .localhost subdomains, IPs, and www.example.com
343+
config.hosts = [
344+
".localhost",
345+
"www.example.com",
346+
IPAddr.new("0.0.0.0/0"), # IPv4
347+
IPAddr.new("::/0"), # IPv6
348+
]
340349
RUBY
341-
unless content.include?("config.hosts << \"www.example.com\"")
350+
unless content.include?("config.hosts = [")
342351
content.sub!("Rails.application.configure do", "Rails.application.configure do\n#{insert}")
343352
end
344353
File.write(test_env_path, content)

0 commit comments

Comments
 (0)