File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed
tests/integration/postgresql Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,15 @@ createuser-{{ index }}:
134
134
{% endif %}
135
135
- user: postgres
136
136
137
+ {% set connection_limit = config.get(' connection_limit' ) %}
138
+ {% if connection_limit %}
139
+ set_user_{{ config['username'] }}_connection_limit :
140
+ cmd.run :
141
+ - name: psql -U postgres -c "ALTER ROLE {{ config[' username' ] }} CONNECTION LIMIT {{ connection_limit }};"
142
+ - unless: psql -U postgres -t -c " SELECT rolconnlimit FROM pg_roles WHERE rolname = ' {{ config[' username' ] }}' ;" | grep -wq {{ connection_limit }}
143
+ - runas: postgres
144
+ {% endif %}
145
+
137
146
# The " replication" and " all" keywords are not real databases but special keywords used for permissions in pg_hba.conf
138
147
{% if config[' database' ] != " replication" and config[' database' ] != ' all' %}
139
148
Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ postgresql:
138
138
address : 10.1.2.0/24
139
139
method : trust
140
140
login : false
141
+ connection_limit : 100
141
142
142
143
- username : example_user_with_role
143
144
type : host
Original file line number Diff line number Diff line change 138
138
its ( 'output' ) { should match /example_role/ }
139
139
end
140
140
141
+ # Assert that connection limit is reflected correctly
142
+ describe sql . query ( "SELECT rolconnlimit FROM pg_roles WHERE rolname='example_role'" ) do
143
+ its ( 'output' ) { should eq ( '100' ) }
144
+ end
145
+
146
+ # Assert that connection limit for other users is the default
147
+ describe sql . query ( "SELECT rolconnlimit FROM pg_roles WHERE rolname='deploy'" ) do
148
+ its ( 'output' ) { should eq ( '-1' ) }
149
+ end
150
+
141
151
# Assert extensions
142
152
describe sql . query ( "SELECT extname FROM pg_extension;" , [ 'db_with_extension' ] ) do
143
153
its ( 'output' ) { should match /pgcrypto/ }
You can’t perform that action at this time.
0 commit comments