gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commite9f950a8e9f950a8reports: G25c soakmree9f950a8/tests/app-auth-unit.hl

1.7 KB

  1. // tests/app-auth-unit.hl — run by tests/app-token.mjs with its own GITORIA_STORAGE: appOfRequest (lib/app-auth.hl) called directly, because no apps API route uses it yet (#44).
  2. // Prints one line per case: `<case> <status or ok>`.
  3. import { now } from 'hl:time'
  4. import { sha256 } from 'hl:crypto'
  5. import { reposTable } from './../lib/repos.hl'
  6. import { removeApp } from './../lib/apps.hl'
  7. import { appsTable } from './../lib/apps-table.hl'
  8. import { issueToken, dropTokensOfApp } from './../lib/app-tokens.hl'
  9. import { appOfRequest } from './../lib/app-auth.hl'
  10. r1 = reposTable.put({ slug = 'one' description = 'x' owner = 'u' created = now() org = '' priv = true })
  11. r2 = reposTable.put({ slug = 'two' description = 'x' owner = 'u' created = now() org = '' priv = false })
  12. a1 = appsTable.put({ repo = r1 name = 'A' hookUrl = 'https://x.worldapi.org/' keyHash = sha256('k1') secret = 's' createdBy = 'u' created = now() lastDelivery = 0 lastStatus = '' })
  13. app1 = appsTable.fetch(a1)
  14. t = issueToken(app1)
  15. static ask = (host, token) => {
  16. headers = { host = host }
  17. if (token != null) { headers['authorization'] = 'Bearer ' + token }
  18. return appOfRequest({ params = {} }, { headers = headers })
  19. }
  20. static show = (label, r) => {
  21. console.log(label + ' ' + (r.error != null ? r.error.status + ' ' + JSON.parse(r.error.body).error.code : 'ok ' + r.app.name + ' ' + r.repo.slug))
  22. }
  23. show('good', ask('one.localhost:1', t.token))
  24. show('none', ask('one.localhost:1', null))
  25. show('unknown', ask('one.localhost:1', 'gat_' + 'b'.repeat(40)))
  26. show('other-repo', ask('two.localhost:1', t.token))
  27. show('no-repo', ask('zzz.localhost:1', t.token))
  28. dropTokensOfApp(a1)
  29. show('dropped', ask('one.localhost:1', t.token))
  30. t2 = issueToken(app1)
  31. appsTable.delete(a1)
  32. show('app-gone', ask('one.localhost:1', t2.token))

Branches

Latest commits

  • e9f950a8reports: G25c soakmre
  • a7783686log: deploy 9f41ffcmre
  • 9f41ffc1log: W30b mergedmre
  • bef635c1Merge branch 'w30b'mre
  • 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
  • c4f6d9e3reports: G25c growth huntmre
  • b88e39f1log: privacy cleanup donemre
  • bfd7826ddocs: neutral example organisation namemre
  • 01b71c2edocs: neutral wording in missions, reports and logmre
  • 3eeea733log: 2026-11-09 PR flow plan and membersmre
  • e7c2ff1fdocs: neutral name for the apps-api reviewmre
  • 120b7abdlog: step 3 queuedmre
  • 358474bflog: P50 livemre
  • 477d7bdcMerge branch 'p50'mre
  • 00efc06fP50 reportmre
  • e3f85afblog: commit mention slipmre
  • 4d1a4cf4log: #25 numbersmre
  • 1af0a60ddocs: H25 run() correctionmre
  • eefa2dbcRepo setting: refuse direct pushes to the main branch (pre-receive over HTTPS and ssh)mre
  • 8c8ba2f1log: PR flow announcedmre