oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "testing"
5
6 "amadan.net/oficina/equipo/internal/equipo/push"
7)
8
9// TestLoggedPushBoundary: logged push, like logged mail, only on loopback
10// or a staging origin, refused at LoadConfig and again by Pusher.
11func TestLoggedPushBoundary(t *testing.T) {
12 for origin, allowed := range map[string]bool{
13 "http://127.0.0.1:4321": true,
14 "https://equipo-staging-0123456789abcdef.bds.oncarlos.com": true,
15 "https://equipo.bds.oncarlos.com": false,
16 "https://equipo-staging-0123456789abcdef.bds.oncarlos.com.evil.test": false,
17 } {
18 env := map[string]string{"EQUIPO_ORIGIN": origin, "EQUIPO_INSTANCE_KEY": "k", "CARLOS_MAIL": "submit", "EQUIPO_ALLOW_LOGGED_PUSH": "1"}
19 cfg, err := LoadConfig(func(k string) string { return env[k] })
20 if (err == nil) != allowed {
21 t.Fatalf("%s: allowed=%v error=%v", origin, allowed, err)
22 }
23 if _, err := Pusher(Config{Origin: origin, InstanceKey: "k", AllowLoggedPush: true}, nil, func(string) string { return "" }); (err == nil) != allowed {
24 t.Fatalf("%s: Pusher allowed=%v error=%v", origin, allowed, err)
25 }
26 if allowed {
27 if tr, err := Pusher(cfg, nil, func(string) string { return "" }); err != nil || tr == nil {
28 t.Fatalf("%s: no logged transport %v", origin, err)
29 } else if _, ok := tr.(push.Logged); !ok {
30 t.Fatalf("%s: %T", origin, tr)
31 }
32 }
33 }
34}
35
36// TestPusherChannels: no push setting is no push at all; CARLOS_PUSH=submit
37// refuses until the platform's push submission exists (the seam).
38func TestPusherChannels(t *testing.T) {
39 cfg := Config{Origin: "https://equipo.bds.oncarlos.com", InstanceKey: "k"}
40 if tr, err := Pusher(cfg, nil, func(string) string { return "" }); tr != nil || err != nil {
41 t.Fatalf("unset: %v %v", tr, err)
42 }
43 _, err := Pusher(cfg, nil, func(k string) string { return map[string]string{push.CarlosPushEnv: "submit"}[k] })
44 if err == nil || err.Error() != copyCarlosPushUnavailable {
45 t.Fatalf("submit: %v", err)
46 }
47}
48
49// TestPusherRefusesBoth: logged push and CARLOS submission together refuse
50// boot, never one silently over the other.
51func TestPusherRefusesBoth(t *testing.T) {
52 cfg := Config{Origin: "http://127.0.0.1:4321", InstanceKey: "k", AllowLoggedPush: true}
53 for _, v := range []string{"submit", "anything"} {
54 _, err := Pusher(cfg, nil, func(k string) string { return map[string]string{push.CarlosPushEnv: v}[k] })
55 if err == nil || err.Error() != copyPushBoth {
56 t.Fatalf("%s: %v", v, err)
57 }
58 }
59}
60