Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

server: document legacy kit wait contract

Neeraj Gupta2a956e9f3e1e
diff --git a/server/ente/legacy_kit.go b/server/ente/legacy_kit.go
index f6b63db9a4..bfbe59a2b0 100644
--- a/server/ente/legacy_kit.go
+++ b/server/ente/legacy_kit.go
@@ -55,11 +55,14 @@ type LegacyKitDownloadContentResponse struct {
}
type LegacyKitRecoverySession struct {
- ID uuid.UUID `json:"id"`
- KitID uuid.UUID `json:"kitID"`
- Status LegacyKitRecoveryStatus `json:"status"`
- WaitTill int64 `json:"waitTill"`
- CreatedAt int64 `json:"createdAt"`
+ ID uuid.UUID `json:"id"`
+ KitID uuid.UUID `json:"kitID"`
+ Status LegacyKitRecoveryStatus `json:"status"`
+ // Remaining microseconds until recovery becomes ready. This follows the
+ // existing emergency legacy recovery API shape, where waitTill is a
+ // duration in API responses, not an epoch timestamp.
+ WaitTill int64 `json:"waitTill"`
+ CreatedAt int64 `json:"createdAt"`
}
type LegacyKitChallengeRequest struct {
diff --git a/server/pkg/controller/legacy_kit/controller_test.go b/server/pkg/controller/legacy_kit/controller_test.go
new file mode 100644
index 0000000000..edd53f4abc
--- /dev/null
+++ b/server/pkg/controller/legacy_kit/controller_test.go
@@ -0,0 +1,43 @@
+package legacy_kit
+
+import (
+ "testing"
+ "time"
+
+ "github.com/ente-io/museum/ente"
+ legacykitrepo "github.com/ente-io/museum/pkg/repo/legacy_kit"
+ timeutil "github.com/ente-io/museum/pkg/utils/time"
+ "github.com/google/uuid"
+ "github.com/stretchr/testify/require"
+)
+
+func TestToRecoverySessionReturnsRemainingWaitTime(t *testing.T) {
+ row := &legacykitrepo.RecoverySessionRow{
+ ID: uuid.New(),
+ KitID: uuid.New(),
+ Status: ente.LegacyKitRecoveryStatusWaiting,
+ WaitTill: timeutil.MicrosecondsAfterHours(1),
+ CreatedAt: timeutil.Microseconds(),
+ }
+
+ session := toRecoverySession(row)
+
+ require.Equal(t, ente.LegacyKitRecoveryStatusWaiting, session.Status)
+ require.Greater(t, session.WaitTill, int64(0))
+ require.LessOrEqual(t, session.WaitTill, time.Hour.Microseconds())
+}
+
+func TestToRecoverySessionMarksExpiredWaitingSessionReady(t *testing.T) {
+ row := &legacykitrepo.RecoverySessionRow{
+ ID: uuid.New(),
+ KitID: uuid.New(),
+ Status: ente.LegacyKitRecoveryStatusWaiting,
+ WaitTill: timeutil.Microseconds() - 1,
+ CreatedAt: timeutil.Microseconds(),
+ }
+
+ session := toRecoverySession(row)
+
+ require.Equal(t, ente.LegacyKitRecoveryStatusReady, session.Status)
+ require.Equal(t, int64(0), session.WaitTill)
+}