From 2cf1b1e255c24d545210c932dbd80f24ef9d432b Mon Sep 17 00:00:00 2001 From: Boris Bobrov Date: Wed, 7 Sep 2016 16:51:05 +0300 Subject: [PATCH] Keep the order of passwords in tests While multiple passwords are stored for a user, only the latest one is used for authentication. When `created_at` in tests get changed, the order of password might change too. Keep the order of passwords by giving earlier passwords an earlier date of creation. Change-Id: I68861bc5c379dcf1cf060081f7802917d6f0c4b9 --- keystone/tests/unit/identity/test_backend_sql.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/keystone/tests/unit/identity/test_backend_sql.py b/keystone/tests/unit/identity/test_backend_sql.py index 199a66b0b3..fbb9e9ae04 100644 --- a/keystone/tests/unit/identity/test_backend_sql.py +++ b/keystone/tests/unit/identity/test_backend_sql.py @@ -560,7 +560,17 @@ class MinimumPasswordAgeTests(test_backend_sql.SqlTests): return self.identity_api.create_user(user) def _update_password_created_at(self, user_id, password_create_at): + # User instance has an attribute password_ref. This attribute is used + # in authentication. It always points to the last created password. The + # order of passwords is determined by `created_at` field. + # By changing `created_at`, this method interferes with password_ref + # behaviour, making it return not last value. That's why all passwords + # except the latest, need to have `created_at` slightly less than + # the latest password. with sql.session_for_write() as session: user_ref = session.query(model.User).get(user_id) + latest_password = user_ref.password_ref + slightly_less = datetime.timedelta(minutes=1) for password_ref in user_ref.local_user.passwords: - password_ref.created_at = password_create_at + password_ref.created_at = password_create_at - slightly_less + latest_password.created_at = password_create_at