|
| 1 | +-- |
| 2 | +-- Tests for password verifiers |
| 3 | +-- |
| 4 | +-- Tests for GUC password_encryption |
| 5 | +SET password_encryption = 'novalue'; -- error |
| 6 | +ERROR: invalid value for parameter "password_encryption": "novalue" |
| 7 | +HINT: Available values: plain, md5, scram, off, on. |
| 8 | +SET password_encryption = true; -- ok |
| 9 | +SET password_encryption = 'md5'; -- ok |
| 10 | +SET password_encryption = 'plain'; -- ok |
| 11 | +SET password_encryption = 'scram'; -- ok |
| 12 | +-- consistency of password entries |
| 13 | +SET password_encryption = 'plain'; |
| 14 | +CREATE ROLE regress_passwd1 PASSWORD 'role_pwd1'; |
| 15 | +SET password_encryption = 'md5'; |
| 16 | +CREATE ROLE regress_passwd2 PASSWORD 'role_pwd2'; |
| 17 | +SET password_encryption = 'on'; |
| 18 | +CREATE ROLE regress_passwd3 PASSWORD 'role_pwd3'; |
| 19 | +SET password_encryption = 'scram'; |
| 20 | +CREATE ROLE regress_passwd4 PASSWORD 'role_pwd4'; |
| 21 | +SET password_encryption = 'plain'; |
| 22 | +CREATE ROLE regress_passwd5 PASSWORD NULL; |
| 23 | +-- check list of created entries |
| 24 | +-- |
| 25 | +-- The scram verifier will look something like: |
| 26 | +-- scram-sha-256:E4HxLGtnRzsYwg==:4096:5ebc825510cb7862efd87dfa638d8337179e6913a724441dc9e888a856fbc10c:e966b1c72fad89d69aaebb156eae04edc9581286f92207c044711e79cd461bee |
| 27 | +-- |
| 28 | +-- Since the salt is random, the exact value stored will be different on every test |
| 29 | +-- run. Use a regular expression to mask the changing parts. |
| 30 | +SELECT rolname, regexp_replace(rolpassword, '(scram-sha-256):([a-zA-Z0-9+/]+==):(\d+):(\w+):(\w+)', '\1:<salt>:\3:<storedkey>:<serverkey>') as rolpassword_masked |
| 31 | + FROM pg_authid |
| 32 | + WHERE rolname LIKE 'regress_passwd%' |
| 33 | + ORDER BY rolname, rolpassword; |
| 34 | + rolname | rolpassword_masked |
| 35 | +-----------------+--------------------------------------------------- |
| 36 | + regress_passwd1 | role_pwd1 |
| 37 | + regress_passwd2 | md54044304ba511dd062133eb5b4b84a2a3 |
| 38 | + regress_passwd3 | md50e5699b6911d87f17a08b8d76a21e8b8 |
| 39 | + regress_passwd4 | scram-sha-256:<salt>:4096:<storedkey>:<serverkey> |
| 40 | + regress_passwd5 | |
| 41 | +(5 rows) |
| 42 | + |
| 43 | +-- Rename a role |
| 44 | +ALTER ROLE regress_passwd3 RENAME TO regress_passwd3_new; |
| 45 | +NOTICE: MD5 password cleared because of role rename |
| 46 | +-- md5 entry should have been removed |
| 47 | +SELECT rolname, rolpassword |
| 48 | + FROM pg_authid |
| 49 | + WHERE rolname LIKE 'regress_passwd3_new' |
| 50 | + ORDER BY rolname, rolpassword; |
| 51 | + rolname | rolpassword |
| 52 | +---------------------+------------- |
| 53 | + regress_passwd3_new | |
| 54 | +(1 row) |
| 55 | + |
| 56 | +ALTER ROLE regress_passwd3_new RENAME TO regress_passwd3; |
| 57 | +-- ENCRYPTED and UNENCRYPTED passwords |
| 58 | +ALTER ROLE regress_passwd1 UNENCRYPTED PASSWORD 'foo'; -- unencrypted |
| 59 | +ALTER ROLE regress_passwd2 UNENCRYPTED PASSWORD 'md5dfa155cadd5f4ad57860162f3fab9cdb'; -- encrypted with MD5 |
| 60 | +SET password_encryption = 'md5'; |
| 61 | +ALTER ROLE regress_passwd3 ENCRYPTED PASSWORD 'foo'; -- encrypted with MD5 |
| 62 | +ALTER ROLE regress_passwd4 ENCRYPTED PASSWORD 'scram-sha-256:VLK4RMaQLCvNtQ==:4096:3ded2376f7aafa93b1bdbd71bcc18b7d6ee50ed018029cc583d152ef3fc7d430:a6dd36dfc94c181956a6ae95f05e01b1864f0a22a2657d1de4ba84d2a24dc438'; -- client-supplied SCRAM verifier, use as it is |
| 63 | +SET password_encryption = 'scram'; |
| 64 | +ALTER ROLE regress_passwd5 ENCRYPTED PASSWORD 'foo'; -- create SCRAM verifier |
| 65 | +CREATE ROLE regress_passwd6 ENCRYPTED PASSWORD 'md53725413363ab045e20521bf36b8d8d7f'; -- encrypted with MD5, use as it is |
| 66 | +SELECT rolname, regexp_replace(rolpassword, '(scram-sha-256):([a-zA-Z0-9+/]+==):(\d+):(\w+):(\w+)', '\1:<salt>:\3:<storedkey>:<serverkey>') as rolpassword_masked |
| 67 | + FROM pg_authid |
| 68 | + WHERE rolname LIKE 'regress_passwd%' |
| 69 | + ORDER BY rolname, rolpassword; |
| 70 | + rolname | rolpassword_masked |
| 71 | +-----------------+--------------------------------------------------- |
| 72 | + regress_passwd1 | foo |
| 73 | + regress_passwd2 | md5dfa155cadd5f4ad57860162f3fab9cdb |
| 74 | + regress_passwd3 | md5530de4c298af94b3b9f7d20305d2a1bf |
| 75 | + regress_passwd4 | scram-sha-256:<salt>:4096:<storedkey>:<serverkey> |
| 76 | + regress_passwd5 | scram-sha-256:<salt>:4096:<storedkey>:<serverkey> |
| 77 | + regress_passwd6 | md53725413363ab045e20521bf36b8d8d7f |
| 78 | +(6 rows) |
| 79 | + |
| 80 | +DROP ROLE regress_passwd1; |
| 81 | +DROP ROLE regress_passwd2; |
| 82 | +DROP ROLE regress_passwd3; |
| 83 | +DROP ROLE regress_passwd4; |
| 84 | +DROP ROLE regress_passwd5; |
| 85 | +DROP ROLE regress_passwd6; |
| 86 | +-- all entries should have been removed |
| 87 | +SELECT rolname, rolpassword |
| 88 | + FROM pg_authid |
| 89 | + WHERE rolname LIKE 'regress_passwd%' |
| 90 | + ORDER BY rolname, rolpassword; |
| 91 | + rolname | rolpassword |
| 92 | +---------+------------- |
| 93 | +(0 rows) |
| 94 | + |
0 commit comments