Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test to reproduce grace period not being honored #3171

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions packages/stream-tests/src/__tests__/capability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,15 @@ describe('CACAO Integration test', () => {
let didKeyWithCapability
let opts
const CACAO_EXPIRATION_WINDOW = 1000 * 60 * 10 // 10 minutes
const expirationTime = new Date(new Date().valueOf() + CACAO_EXPIRATION_WINDOW)

// Set curren time forward far enough into the future that the CACAO being used has expired
// Set current time forward far enough into the future that the CACAO being used has expired
function expireCacao() {
const twoDays = 48 * 3600 * 1000 // in ms
MockDate.set(new Date(new Date().valueOf() + twoDays).toISOString()) // Plus 2 days
}

beforeEach(async () => {
const expirationTime = new Date(new Date().valueOf() + CACAO_EXPIRATION_WINDOW)
didKeyWithCapability = await addCapToDid(
wallet,
didKey,
Expand Down Expand Up @@ -565,6 +565,32 @@ describe('CACAO Integration test', () => {
1000 * 60
)

test(
'Can update with expired capability within 24 hour grace period',
async () => {
const doc = await TileDocument.create(
ceramic,
CONTENT0,
{
controllers: [PARENT_WALLET_ADDRESS],
},
opts
)

// Ceramic uses a 24 hour grace period during which it continues to accept expired CACAOs.
// So we set the current time to 12 hours past the CACAO expiration time, which should still
// be considered within the grace period.
const twelveHours = 1000 * 60 * 60 * 12 // in ms
const withinGracePeriod = new Date(expirationTime.valueOf() + twelveHours)
MockDate.set(withinGracePeriod.toISOString())

await doc.update(CONTENT1, null, opts)

expect(doc.content).toEqual(CONTENT1)
},
1000 * 60
)

test('overwrite expired capability when SYNC_ALWAYS', async () => {
const opts = { asDID: didKeyWithCapability, anchor: false, publish: false }
const tile = await TileDocument.deterministic(
Expand Down