From ce241fa40adee2b12f8e225db98e09a45bc2acbb Mon Sep 17 00:00:00 2001 From: Crystal Date: Mon, 20 Mar 2023 22:57:26 +0000 Subject: [PATCH] Fix certificate renewal (#209) A database bug in xorm.go prevents the pages-server from saving a renewed certificate for a domain that already has one in the database. Co-authored-by: crystal Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/209 Reviewed-by: 6543 <6543@obermui.de> Co-authored-by: Crystal Co-committed-by: Crystal --- server/database/xorm.go | 2 +- server/database/xorm_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/database/xorm.go b/server/database/xorm.go index a14f887..32d5bc2 100644 --- a/server/database/xorm.go +++ b/server/database/xorm.go @@ -64,7 +64,7 @@ func (x xDB) Put(domain string, cert *certificate.Resource) error { } defer sess.Close() - if exist, _ := sess.ID(c.Domain).Exist(); exist { + if exist, _ := sess.ID(c.Domain).Exist(new(Cert)); exist { if _, err := sess.ID(c.Domain).Update(c); err != nil { return err } diff --git a/server/database/xorm_test.go b/server/database/xorm_test.go index 9c032ee..50d8a7f 100644 --- a/server/database/xorm_test.go +++ b/server/database/xorm_test.go @@ -37,7 +37,7 @@ func TestSanitizeWildcardCerts(t *testing.T) { })) // update existing cert - assert.Error(t, certDB.Put(".wildcard.de", &certificate.Resource{ + assert.NoError(t, certDB.Put(".wildcard.de", &certificate.Resource{ Domain: "*.wildcard.de", Certificate: localhost_mock_directory_certificate, }))