From a328e7ccc4f94e19cddfe5894636228663f5c7fa Mon Sep 17 00:00:00 2001 From: E99p1ant Date: Sun, 5 Jun 2022 13:34:21 +0800 Subject: access_token: encrypt access token with SHA256 (#7008) * access_token: encrypt access token with SHA256 * revert list access token * fix lint * generate schemadoc * add database migrations * fix tests * fix tests * add test case for access token golden * fix test in postgres * `Sha256` -> `SHA256` * Use GORM for migration * task generate-schemadoc * Use unique * change migration name * allow read * task generate-schemadoc * add changelog * fix lint error * update changelog * remove Debug * add comments Co-authored-by: Joe Chen --- internal/db/backup_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'internal/db/backup_test.go') diff --git a/internal/db/backup_test.go b/internal/db/backup_test.go index 4bbef8f6..e30ac7a2 100644 --- a/internal/db/backup_test.go +++ b/internal/db/backup_test.go @@ -63,6 +63,7 @@ func setupDBToDump(t *testing.T, db *gorm.DB) { UserID: 1, Name: "test1", Sha1: cryptoutil.SHA1("2910d03d-c0b5-4f71-bad5-c4086e4efae3"), + SHA256: cryptoutil.SHA256(cryptoutil.SHA1("2910d03d-c0b5-4f71-bad5-c4086e4efae3")), CreatedUnix: 1588568886, UpdatedUnix: 1588572486, // 1 hour later }, @@ -70,12 +71,21 @@ func setupDBToDump(t *testing.T, db *gorm.DB) { UserID: 1, Name: "test2", Sha1: cryptoutil.SHA1("84117e17-7e67-4024-bd04-1c23e6e809d4"), + SHA256: cryptoutil.SHA256(cryptoutil.SHA1("84117e17-7e67-4024-bd04-1c23e6e809d4")), CreatedUnix: 1588568886, }, &AccessToken{ UserID: 2, Name: "test1", Sha1: cryptoutil.SHA1("da2775ce-73dd-47ba-b9d2-bbcc346585c4"), + SHA256: cryptoutil.SHA256(cryptoutil.SHA1("da2775ce-73dd-47ba-b9d2-bbcc346585c4")), + CreatedUnix: 1588568886, + }, + &AccessToken{ + UserID: 2, + Name: "test2", + Sha1: cryptoutil.SHA256(cryptoutil.SHA1("1b2dccd1-a262-470f-bb8c-7fc73192e9bb"))[:40], + SHA256: cryptoutil.SHA256(cryptoutil.SHA1("1b2dccd1-a262-470f-bb8c-7fc73192e9bb")), CreatedUnix: 1588568886, }, -- cgit v1.2.3