@@ -194,6 +194,7 @@ class PostgresServer
194194 attr_reader :port
195195 attr_reader :conninfo
196196 attr_reader :unix_socket
197+ attr_reader :version
197198
198199 ### Set up a PostgreSQL database instance for testing.
199200 def initialize ( name , port : 23456 , postgresql_conf : '' )
@@ -205,6 +206,7 @@ def initialize(name, port: 23456, postgresql_conf: '')
205206 @pgdata = @test_dir + 'data'
206207 @logfile = @test_dir + 'setup.log'
207208 @pg_bindir = pg_bindir
209+ @version = pg_version
208210 @unix_socket = @test_dir . to_s
209211 @conninfo = "host=localhost port=#{ @port } dbname=test sslrootcert=#{ @pgdata + 'ruby-pg-ca-cert' } sslcert=#{ @pgdata + 'ruby-pg-client-cert' } sslkey=#{ @pgdata + 'ruby-pg-client-key' } "
210212
@@ -267,8 +269,13 @@ def setup_cluster(postgresql_conf)
267269 ssl_cert_file = 'ruby-pg-server-cert'
268270 ssl_key_file = 'ruby-pg-server-key'
269271 fsync = off
270- #{ postgresql_conf }
271272 EOT
273+ if @version >= 18
274+ fd . puts <<~EOT
275+ oauth_validator_libraries = '#{ TEST_DIRECTORY } /spec/oauth/dummy_validator'
276+ EOT
277+ end
278+ fd . puts postgresql_conf
272279 end
273280
274281 # Enable MD5 authentication in hba config
@@ -278,6 +285,12 @@ def setup_cluster(postgresql_conf)
278285 # TYPE DATABASE USER ADDRESS METHOD
279286 host all testusermd5 ::1/128 md5
280287 EOT
288+ if @version >= 18
289+ fd . puts <<~EOT
290+ host all testuseroauth 127.0.0.1/32 oauth scope=test issuer="http://localhost:#{ @port + 3 } "
291+ host all testuseroauth ::1/32 oauth scope=test issuer="http://localhost:#{ @port + 3 } "
292+ EOT
293+ end
281294 fd . puts hba_content
282295 end
283296
@@ -340,6 +353,10 @@ def pg_bindir
340353 rescue
341354 nil
342355 end
356+
357+ def pg_version
358+ `#{ pg_bin_path ( "pg_ctl" ) } --version` [ /pg_ctl \( PostgreSQL\) (\d +)/ , 1 ] &.to_i
359+ end
343360 end
344361
345362 class CertGenerator
@@ -682,6 +699,7 @@ def set_etc_hosts(hostaddr, hostname)
682699 config . filter_run_excluding ( :postgresql_12 ) if PG . library_version < 120000
683700 config . filter_run_excluding ( :postgresql_14 ) if PG . library_version < 140000
684701 config . filter_run_excluding ( :postgresql_17 ) if PG . library_version < 170000
702+ config . filter_run_excluding ( :postgresql_18 ) if PG . library_version < 180000
685703 config . filter_run_excluding ( :unix_socket ) if RUBY_PLATFORM =~/mingw|mswin/i
686704 config . filter_run_excluding ( :scheduler ) if RUBY_VERSION < "3.0" || ( RUBY_PLATFORM =~ /mingw|mswin/ && RUBY_VERSION < "3.1" ) || !Fiber . respond_to? ( :scheduler )
687705 config . filter_run_excluding ( :scheduler_address_resolve ) if RUBY_VERSION < "3.1"
0 commit comments