diff --git a/khatru/utils.go b/khatru/utils.go index b11f138..10b982d 100644 --- a/khatru/utils.go +++ b/khatru/utils.go @@ -74,6 +74,13 @@ func IsAuthed(ctx context.Context, pubkey nostr.PubKey) bool { return false } +// ForceSetAuthed modifies the context to insert a custom authed public key. +// It can be used in testing or other rare scenarios for making requests as if a given public key +// was authenticated when in fact it didn't perform any of the authentication rituals. +func ForceSetAuthed(ctx context.Context, pubkey nostr.PubKey) context.Context { + return context.WithValue(ctx, nip86HeaderAuthKey, pubkey) +} + // IsInternalCall returns true when a call to QueryEvents, for example, is being made because of a deletion // or expiration request. func IsInternalCall(ctx context.Context) bool {