| 1160 | } |
| 1161 | |
| 1162 | func TestMaskToken(t *testing.T) { |
| 1163 | tests := []struct { |
| 1164 | name string |
| 1165 | token string |
| 1166 | want string |
| 1167 | }{ |
| 1168 | { |
| 1169 | name: "empty token", |
| 1170 | token: "", |
| 1171 | want: "", |
| 1172 | }, |
| 1173 | { |
| 1174 | name: "classic personal access token", |
| 1175 | token: "ghp_abc123", |
| 1176 | want: "ghp_******", |
| 1177 | }, |
| 1178 | { |
| 1179 | name: "oauth token", |
| 1180 | token: "gho_abc123", |
| 1181 | want: "gho_******", |
| 1182 | }, |
| 1183 | { |
| 1184 | name: "user-to-server token", |
| 1185 | token: "ghu_abc123", |
| 1186 | want: "ghu_******", |
| 1187 | }, |
| 1188 | { |
| 1189 | name: "server-to-server token", |
| 1190 | token: "ghs_abc123", |
| 1191 | want: "ghs_******", |
| 1192 | }, |
| 1193 | { |
| 1194 | name: "refresh token", |
| 1195 | token: "ghr_abc123", |
| 1196 | want: "ghr_******", |
| 1197 | }, |
| 1198 | { |
| 1199 | name: "fine-grained personal access token with internal underscore", |
| 1200 | token: "github_pat_abc_123456", |
| 1201 | want: "github_pat_**********", |
| 1202 | }, |
| 1203 | { |
| 1204 | name: "token with multiple internal underscores masks everything after prefix", |
| 1205 | token: "ghs_aaa_bbb_ccc", |
| 1206 | want: "ghs_***********", |
| 1207 | }, |
| 1208 | { |
| 1209 | name: "unknown prefix is fully masked", |
| 1210 | token: "unknown_abc123", |
| 1211 | want: "**************", |
| 1212 | }, |
| 1213 | { |
| 1214 | name: "token without underscore is fully masked", |
| 1215 | token: "abc123", |
| 1216 | want: "******", |
| 1217 | }, |
| 1218 | { |
| 1219 | name: "token equal to known prefix has nothing to mask", |