Skip to content

Commit 5eee179

Browse files
justindellJustin Dellaidanharan
authored
Support trust_server_certificate option in dbconsole (#1383)
* Support trust_server_certificate option in dbconsole ODBC Driver 18+ encrypts connections by default and validates SSL certificates, causing `rails dbconsole` to fail against SQL Server instances using self-signed certificates (e.g. Docker). Pass the -C flag to sqlcmd when trust_server_certificate is set in database.yml. --------- Co-authored-by: Justin Dell <justin.dell@healthstrategyllc.com> Co-authored-by: Aidan Haran <aidanharan@yahoo.com>
1 parent 3231ec0 commit 5eee179

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: CI
22

3-
on:
4-
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
8-
schedule:
9-
- cron: '0 4 * * 0'
3+
on: [push, pull_request]
104

115
jobs:
126
test:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
3+
#### Added
4+
5+
- [#1383](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1383) Support trust_server_certificate option in dbconsole.
6+
17
## v8.1.2
28

39
#### Fixed

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ gemspec
99
gem "bcrypt"
1010
gem "pg", "1.5.9"
1111
gem "sqlite3", ">= 2.1"
12-
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
12+
gem "tzinfo-data"
1313
gem "benchmark-ips"
14-
gem "minitest", ">= 5.15.0"
14+
gem "minitest", "~> 6.0"
15+
gem "minitest-mock"
1516
gem "msgpack", ">= 1.7.0"
1617

1718
if ENV["RAILS_SOURCE"]

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def dbconsole(config, options = {})
104104
args += ["-d", config.database.to_s] if config.database
105105
args += ["-U", sqlserver_config[:username].to_s] if sqlserver_config[:username]
106106
args += ["-P", sqlserver_config[:password].to_s] if sqlserver_config[:password]
107+
args += ["-C"] if sqlserver_config[:trust_server_certificate]
107108

108109
if sqlserver_config[:host]
109110
host_arg = "tcp:#{sqlserver_config[:host]}"
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# frozen_string_literal: true
22

33
class DbConsole < ActiveRecord::TestCase
4-
subject { ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter }
4+
subject { ActiveRecord::ConnectionAdapters::SQLServerAdapter }
55

6-
it "uses sqlplus to connect to database" do
7-
subject.expects(:find_cmd_and_exec).with("sqlcmd", "-d", "db", "-U", "user", "-P", "secret", "-S", "tcp:localhost,1433")
6+
it "uses sqlcmd to connect to database" do
7+
subject.expects(:find_cmd_and_exec).with("sqlcmd", "-d", "db", "-U", "user", "-P", "secret", "-C", "-S",
8+
"tcp:localhost,1433")
89

9-
config = make_db_config(adapter: "sqlserver", database: "db", username: "user", password: "secret", host: "localhost", port: 1433)
10+
config = make_db_config(adapter: "sqlserver", database: "db", username: "user", password: "secret",
11+
host: "localhost", port: 1433, trust_server_certificate: true)
1012

1113
subject.dbconsole(config)
1214
end

0 commit comments

Comments
 (0)