package api
import (
"context"
"testing"
)
type modForum struct {
ForumStore
on bool
}
func (m modForum) ModerationEnabled(string) bool { return m.on }
// A poster can ask whether their post will be held, BEFORE posting.
//
// The state was readable two ways and neither served the poster:
// forum-queue carries a clean `enabled` flag and needs the moderation
// letter, so it answers 403 to exactly the person it holds; and the
// public modlog records every toggle but is EMPTY on a repository that
// has never toggled, so reading it means assuming the default. The
// poster learned the rule from staged:true in the write response, after
// posting (53589c4a64d3).
//
// Found by jva, and sharpened by their adversarial subagent, which
// falsified their first headline — "no op asks whether a forum is
// moderated" — in five minutes. What survived is the better finding:
// the state is published to the moderators it exempts and withheld from
// the authors it holds.
func TestAPosterCanAskWhetherTheirPostWillBeHeld(t *testing.T) {
trusted := func(account, _ string) bool { return account == "mod" }
for _, c := range []struct {
what string
on bool
who string
moderated, yours bool
}{
{"moderation off", false, "jan", false, false},
{"on, untrusted poster", true, "jan", true, true},
// A moderator sees a moderated forum that will not hold THEM:
// two different questions, and conflating them would tell a
// moderator their posts are staged when they never are.
{"on, moderator", true, "mod", true, false},
// A signed-out reader is not a poster; claiming their posts
// would be held asserts something about no account at all.
{"on, signed out", true, "", true, false},
} {
d := Deps{Forum: modForum{on: c.on}, TrustedAuthor: trusted}
got := forumModerationFor(context.Background(), d, "alpha", c.who)
if got.moderated != c.moderated || got.yours != c.yours {
t.Errorf("FAIL [%s]: moderated=%v yourPostsHeld=%v, want %v/%v",
c.what, got.moderated, got.yours, c.moderated, c.yours)
continue
}
t.Logf("ok [%s]: moderated=%v yourPostsHeld=%v", c.what, got.moderated, got.yours)
}
}