feat: add assessment, privacy and support flows
This commit is contained in:
1 parent
ee3738ee73
commit
e4f24fa202
339 files changed
+56454
-1126
No files matched your search
@@ -11,24 +11,28 @@ import (
|
||||
|
||||
// directPublicationReaders are the only queries that may name the table
|
||||
// candidate_publications. The first three are the candidate's own settings
|
||||
// queries; every read on behalf of an organization must go through the view
|
||||
// candidate_effective_publications (published and backed by an unrevoked C2)
|
||||
// and exclude the hidden organizations, as ReadPublicationVisibleToOrganization
|
||||
// does. A new query that reads the table directly fails this test, so it
|
||||
// cannot leak a closed or revoked publication by accident.
|
||||
// queries; the remaining reads are narrowly scoped lock/recheck operations
|
||||
// that require current C2. Organization reads also exclude hidden
|
||||
// organizations, and candidate preview reads remain owner-scoped. A new
|
||||
// query that reads the table directly fails this test until it is reviewed.
|
||||
//
|
||||
// Only queries/*.sql are covered: the project keeps SQL in sqlc queries and
|
||||
// migrations, and the standards forbid raw SQL in Go code.
|
||||
var directPublicationReaders = []string{
|
||||
"ReadCandidatePrivacySettings",
|
||||
"ReadCandidatePublication",
|
||||
"InsertCandidatePublication",
|
||||
"UpdateCandidatePublication",
|
||||
}
|
||||
|
||||
var ownerScopedPublicationQueries = []string{
|
||||
"LockPublicationForCandidatePreview",
|
||||
"LockVisiblePublicationForView",
|
||||
"LockCandidatePublicationForConsentRevocation",
|
||||
}
|
||||
|
||||
var ownerPreviewQueries = []string{"ReadCandidateViewSourceForPreview"}
|
||||
|
||||
var (
|
||||
// sqlc accepts both comment forms and tolerates trailing whitespace.
|
||||
queryHeaderPattern = regexp.MustCompile(`(?m)^(?:--|/\*)[ \t]*name:[ \t]+(\w+)[ \t]+:\w+[ \t]*(?:\*/)?[ \t]*$`)
|
||||
@@ -66,11 +70,11 @@ func TestOnlyTheSettingsQueriesReadThePublicationTableDirectly(t *testing.T) {
|
||||
// Comments may name the table; statements may not.
|
||||
statement := lineComment.ReplaceAllString(blockComment.ReplaceAllString(text[header[1]:end], ""), "")
|
||||
name := text[header[2]:header[3]]
|
||||
statements[name] = strings.Join(strings.Fields(statement), " ")
|
||||
if publicationTableName.MatchString(statement) {
|
||||
found = append(found, name)
|
||||
statements[name] = strings.Join(strings.Fields(statement), " ")
|
||||
}
|
||||
if effectiveViewName.MatchString(statement) && !hiddenTableName.MatchString(statement) {
|
||||
if effectiveViewName.MatchString(statement) && !hiddenTableName.MatchString(statement) && !slices.Contains(ownerPreviewQueries, name) {
|
||||
t.Errorf("%s reads candidate_effective_publications without excluding candidate_hidden_organizations", name)
|
||||
}
|
||||
}
|
||||
@@ -81,9 +85,6 @@ func TestOnlyTheSettingsQueriesReadThePublicationTableDirectly(t *testing.T) {
|
||||
if !slices.Equal(found, want) {
|
||||
t.Fatalf("queries that name candidate_publications = %v, want only settings queries and owner-scoped consent revocation: %v", found, want)
|
||||
}
|
||||
if strings.Contains(strings.Join(found, ","), "Visible") {
|
||||
t.Fatal("the organization-facing read names the table directly")
|
||||
}
|
||||
closeQuery := strings.ToLower(statements["LockCandidatePublicationForConsentRevocation"])
|
||||
for _, required := range []string{
|
||||
"select greatest(candidate_publications.published_at, consent_records.revoked_at)",
|
||||
@@ -100,7 +101,53 @@ func TestOnlyTheSettingsQueriesReadThePublicationTableDirectly(t *testing.T) {
|
||||
t.Errorf("consent revocation query lacks %q: %s", required, closeQuery)
|
||||
}
|
||||
}
|
||||
settingsQuery := strings.ToLower(statements["ReadCandidatePrivacySettings"])
|
||||
for _, required := range []string{
|
||||
"users.id = sqlc.arg(user_id)",
|
||||
"left join candidate_publications",
|
||||
"left join consent_records",
|
||||
"left join candidate_search_statuses",
|
||||
"from candidate_hidden_organizations",
|
||||
} {
|
||||
if !strings.Contains(settingsQuery, required) {
|
||||
t.Errorf("candidate settings query lacks %q: %s", required, settingsQuery)
|
||||
}
|
||||
}
|
||||
for _, forbidden := range []string{"candidate_profiles", "profile_claims", "candidate_questionnaires", "contact_email", "contact_phone"} {
|
||||
if strings.Contains(settingsQuery, forbidden) {
|
||||
t.Errorf("candidate settings query reaches private profile data %q: %s", forbidden, settingsQuery)
|
||||
}
|
||||
}
|
||||
if strings.Contains(closeQuery, "update candidate_publications") || strings.Contains(closeQuery, "set state = 'closed'") {
|
||||
t.Fatalf("consent revocation query rewrites the stored publication instead of preserving its ledger link: %s", closeQuery)
|
||||
}
|
||||
previewQuery := strings.ToLower(statements["ReadCandidateViewSourceForPreview"])
|
||||
for _, required := range []string{
|
||||
"from candidate_effective_publications as effective",
|
||||
"where effective.user_id = sqlc.arg(candidate_id)",
|
||||
"claim.kind in ('stack', 'role', 'experience')",
|
||||
"coalesce(questionnaire.work_formats, '{}'::text[])",
|
||||
} {
|
||||
if !strings.Contains(previewQuery, required) {
|
||||
t.Errorf("owner preview query lacks %q: %s", required, previewQuery)
|
||||
}
|
||||
}
|
||||
visibleLock := strings.ToLower(statements["LockVisiblePublicationForView"])
|
||||
for _, required := range []string{
|
||||
"candidate_publications.user_id = sqlc.arg(candidate_id)",
|
||||
"candidate_publications.state = 'published'",
|
||||
"candidate_publications.consent_record_id = sqlc.arg(consent_record_id)",
|
||||
"consent_records.purpose = 'c2'",
|
||||
"consent_records.revoked_at is null",
|
||||
"candidate_hidden_organizations",
|
||||
"for share of candidate_publications, consent_records",
|
||||
} {
|
||||
if !strings.Contains(visibleLock, required) {
|
||||
t.Errorf("organization card lock lacks %q: %s", required, visibleLock)
|
||||
}
|
||||
}
|
||||
visibleSource := strings.ToLower(statements["ListVisibleCandidateViewSources"])
|
||||
if !effectiveViewName.MatchString(visibleSource) || !hiddenTableName.MatchString(visibleSource) {
|
||||
t.Errorf("organization cohort source must use the effective publication view and hidden-organization filter: %s", visibleSource)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user