(self)
| 144 | USERS = [] |
| 145 | |
| 146 | def setUp(self): |
| 147 | super().setUp() |
| 148 | |
| 149 | if not self.cluster.is_managed(): |
| 150 | self.skipTest('unmanaged cluster') |
| 151 | |
| 152 | self.cluster.reset_hba() |
| 153 | |
| 154 | create_script = [] |
| 155 | for username, method, password in self.USERS: |
| 156 | if method == 'scram-sha-256' and self.server_version.major < 10: |
| 157 | continue |
| 158 | |
| 159 | # if this is a SCRAM password, we need to set the encryption method |
| 160 | # to "scram-sha-256" in order to properly hash the password |
| 161 | if method == 'scram-sha-256': |
| 162 | create_script.append( |
| 163 | "SET password_encryption = 'scram-sha-256';" |
| 164 | ) |
| 165 | |
| 166 | create_script.append( |
| 167 | 'CREATE ROLE "{}" WITH LOGIN{};'.format( |
| 168 | username, |
| 169 | f' PASSWORD E{(password or "")!r}' |
| 170 | ) |
| 171 | ) |
| 172 | |
| 173 | # to be courteous to the MD5 test, revert back to MD5 after the |
| 174 | # scram-sha-256 password is set |
| 175 | if method == 'scram-sha-256': |
| 176 | create_script.append( |
| 177 | "SET password_encryption = 'md5';" |
| 178 | ) |
| 179 | |
| 180 | if _system != 'Windows' and method != 'gss': |
| 181 | self.cluster.add_hba_entry( |
| 182 | type='local', |
| 183 | database='postgres', user=username, |
| 184 | auth_method=method) |
| 185 | |
| 186 | self.cluster.add_hba_entry( |
| 187 | type='host', address=ipaddress.ip_network('127.0.0.0/24'), |
| 188 | database='postgres', user=username, |
| 189 | auth_method=method) |
| 190 | |
| 191 | self.cluster.add_hba_entry( |
| 192 | type='host', address=ipaddress.ip_network('::1/128'), |
| 193 | database='postgres', user=username, |
| 194 | auth_method=method) |
| 195 | |
| 196 | # Put hba changes into effect |
| 197 | self.cluster.reload() |
| 198 | |
| 199 | create_script = '\n'.join(create_script) |
| 200 | self.loop.run_until_complete(self.con.execute(create_script)) |
| 201 | |
| 202 | def tearDown(self): |
| 203 | # Reset cluster's pg_hba.conf since we've meddled with it |
nothing calls this directly
no test coverage detected