Commit ad7f4ea
authored
refactor: extract encryptTokenPair utility (#584)
## Summary
- Extracts a shared `encryptTokenPair(accessToken, refreshToken,
encryptionKey)` utility in `auth/crypto.ts` that encrypts an
access/refresh token pair, returning `null` for unprovided tokens and
throwing on encryption failure
- Replaces 3 inline try/catch encryption blocks in `router.ts`
(`handleCreateSession` and `handleSessionWsToken`) with calls to the
shared utility
- Callers decide error policy: `handleCreateSession` catches and returns
500, `handleSessionWsToken` catches and continues with null tokens
## Test plan
- [x] 5 new unit tests for `encryptTokenPair` covering: both undefined,
access-only, refresh-only, both provided (with round-trip decryption
verification), and invalid key (throws)
- [x] All 1039 existing control-plane tests pass
- [x] Typecheck passes
- [x] Lint passes
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Unified encryption of access and refresh tokens into a single
token-pair flow and tightened error handling so encryption failures now
surface as errors instead of being partially ignored.
* **Tests**
* Added tests covering token-pair encryption, missing-token cases,
successful encrypt/decrypt, and failure/error scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 6073d58 commit ad7f4ea
3 files changed
Lines changed: 95 additions & 43 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
4 | 11 | | |
5 | 12 | | |
6 | 13 | | |
| |||
153 | 160 | | |
154 | 161 | | |
155 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
156 | 210 | | |
157 | 211 | | |
158 | 212 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
111 | 128 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
924 | 924 | | |
925 | 925 | | |
926 | 926 | | |
927 | | - | |
928 | | - | |
| 927 | + | |
929 | 928 | | |
930 | | - | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
931 | 933 | | |
932 | 934 | | |
933 | | - | |
| 935 | + | |
934 | 936 | | |
935 | 937 | | |
936 | 938 | | |
937 | 939 | | |
938 | 940 | | |
939 | | - | |
940 | | - | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
946 | | - | |
947 | | - | |
948 | | - | |
949 | 941 | | |
950 | 942 | | |
951 | 943 | | |
| |||
1725 | 1717 | | |
1726 | 1718 | | |
1727 | 1719 | | |
1728 | | - | |
1729 | | - | |
1730 | | - | |
1731 | | - | |
1732 | | - | |
1733 | | - | |
1734 | | - | |
1735 | | - | |
1736 | | - | |
1737 | | - | |
1738 | | - | |
1739 | | - | |
1740 | | - | |
1741 | | - | |
1742 | | - | |
1743 | | - | |
1744 | | - | |
1745 | | - | |
1746 | | - | |
1747 | | - | |
1748 | | - | |
1749 | | - | |
1750 | | - | |
1751 | | - | |
1752 | | - | |
| 1720 | + | |
| 1721 | + | |
1753 | 1722 | | |
1754 | | - | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
1755 | 1736 | | |
1756 | | - | |
| 1737 | + | |
1757 | 1738 | | |
1758 | 1739 | | |
1759 | 1740 | | |
| |||
0 commit comments