TestHamrpassRejectsControlChars: a key with an embedded escape / NUL / DEL must be rejected by hamrpassValidate, not persisted, else every dial-out errors with net/http's cryptic "invalid header field value for Authorization". Real hamrpass keys are ASCII-printable.
(t *testing.T)
| 3047 | |
| 3048 | // TestHamrpassRejectsTooShort: a key under hamrpassMinKeyLen is refused |
| 3049 | // without touching the profile or the active selection. |
| 3050 | func TestHamrpassRejectsTooShort(t *testing.T) { |
| 3051 | m := newTestModel(t, func(http.ResponseWriter, *http.Request) {}) |
| 3052 | beforeActive := m.cfg.Active |
| 3053 | beforeKey := m.cfg.Models["hamrpass"].Key |
| 3054 | m2, _ := m.runSlash("/hamrpass abc") |
| 3055 | final := m2.(Model) |
| 3056 | if final.cfg.Active != beforeActive { |
| 3057 | t.Fatalf("active changed on rejected key: %q", final.cfg.Active) |
| 3058 | } |
| 3059 | if final.cfg.Models["hamrpass"].Key != beforeKey { |
| 3060 | t.Fatalf("rejected key was stored: %q", final.cfg.Models["hamrpass"].Key) |
| 3061 | } |
| 3062 | out := stripANSI(final.scroll.String()) |
| 3063 | // New wording stays consistent with the popover hint: |
| 3064 | // "N/16 chars · keep typing". |
| 3065 | if !strings.Contains(out, "/16 chars") || !strings.Contains(out, "keep typing") { |
| 3066 | t.Fatalf("expected length hint in scrollback:\n%s", out) |
| 3067 | } |
| 3068 | } |
| 3069 | |
| 3070 | // TestHamrpassRejectsControlChars: a key with an embedded escape / NUL / DEL must |
| 3071 | // be rejected by hamrpassValidate, not persisted, else every dial-out errors |
| 3072 | // with net/http's cryptic "invalid header field value for Authorization". Real |
| 3073 | // hamrpass keys are ASCII-printable. |
| 3074 | func TestHamrpassRejectsControlChars(t *testing.T) { |
| 3075 | cases := map[string]string{ |
| 3076 | "NUL": "hp_secret_key_with\x00null", |
| 3077 | "ESC": "hp_secret_key_with\x1bescape", |
| 3078 | "DEL": "hp_secret_key_with\x7fdel", |
| 3079 | "non-ASCII": "hp_secret_key_with_ümlaut123", |
| 3080 | "raw newline": "hp_key_one\nhp_key_two_X12", |
| 3081 | } |
| 3082 | for name, badKey := range cases { |
nothing calls this directly
no test coverage detected