1- import { gitInfo } from "../git" ;
1+ import { gitInfo , sanitizeGitRemote } from "../git" ;
22
33describe ( "Git integration" , ( ) => {
44 it ( "Returns commit, branch, message, committer, and remoteUrl" , async ( ) => {
@@ -17,3 +17,78 @@ describe("Git integration", () => {
1717 expect ( info . branch ) . toBeDefined ( ) ;
1818 } ) ;
1919} ) ;
20+
21+ describe ( "strip usernames/passwords from git remotes" , ( ) => {
22+ it ( "returns empty for unknown remotes" , ( ) => {
23+ let clean = sanitizeGitRemote ( "https://un@gitlab.com/apollographql/test" ) ;
24+ expect ( clean ) . toBeNull ( ) ;
25+ } ) ;
26+ it ( "removes username from remote with only a username present" , ( ) => {
27+ let clean = sanitizeGitRemote (
28+ "https://un@bitbucket.com/apollographql/test"
29+ ) ;
30+ expect ( clean ) . toEqual ( "https://REDACTED@bitbucket.com/apollographql/test" ) ;
31+ } ) ;
32+ it ( "does not mind case" , ( ) => {
33+ let clean = sanitizeGitRemote ( "https://un@GITHUB.com/apollographql/test" ) ;
34+ expect ( clean ) . toEqual ( "https://REDACTED@GITHUB.com/apollographql/test" ) ;
35+ } ) ;
36+ it ( "strips usernames from ssh urls" , ( ) => {
37+ let clean = sanitizeGitRemote ( "ssh://un%401@github.com/apollographql/test" ) ;
38+ expect ( clean ) . toEqual ( "REDACTED@github.com:apollographql/test" ) ;
39+ } ) ;
40+ it ( "works properly with (allowed) special characters in username/password" , ( ) => {
41+ let clean = sanitizeGitRemote (
42+ "https://un:p%40ssw%3Ard@github.com/apollographql/test"
43+ ) ;
44+ expect ( clean ) . toEqual ( "https://REDACTED@github.com/apollographql/test" ) ;
45+
46+ let bbClean = sanitizeGitRemote (
47+ "https://un:p%40ssw%3Ard@bitbucket.com/apollographql/test"
48+ ) ;
49+ expect ( bbClean ) . toEqual (
50+ "https://REDACTED@bitbucket.com/apollographql/test"
51+ ) ;
52+ } ) ;
53+ it ( "works with non-url remotes from github with git user ONLY" , ( ) => {
54+ let clean = sanitizeGitRemote (
55+ "git@github.com:apollographql/apollo-tooling.git"
56+ ) ;
57+ expect ( clean ) . toEqual ( "git@github.com:apollographql/apollo-tooling.git" ) ;
58+
59+ let clean2 = sanitizeGitRemote (
60+ "bob@github.com:apollographql/apollo-tooling.git"
61+ ) ;
62+ expect ( clean2 ) . toEqual (
63+ "REDACTED@github.com:apollographql/apollo-tooling.git"
64+ ) ;
65+ } ) ;
66+ it ( "works with non-url remotes from bitbucket with git user ONLY" , ( ) => {
67+ let clean = sanitizeGitRemote (
68+ "git@bitbucket.com:apollographql/apollo-tooling.git"
69+ ) ;
70+ expect ( clean ) . toEqual ( "git@bitbucket.com:apollographql/apollo-tooling.git" ) ;
71+
72+ let clean2 = sanitizeGitRemote (
73+ "bob@bitbucket.com:apollographql/apollo-tooling.git"
74+ ) ;
75+ expect ( clean2 ) . toEqual (
76+ "REDACTED@bitbucket.com:apollographql/apollo-tooling.git"
77+ ) ;
78+ } ) ;
79+ it ( "does not allow non-url remotes from unrecognized providers (not github)" , ( ) => {
80+ let clean = sanitizeGitRemote (
81+ "git@lab.com:apollographql/apollo-tooling.git"
82+ ) ;
83+ expect ( clean ) . toBeNull ( ) ;
84+ } ) ;
85+ // TODO maybe fix this in the future?
86+ // git-url-parse right now just uses the dirty `href` if the protocol is unknow
87+ // https://github.com/IonicaBizau/git-url-parse/blob/master/lib/index.js#L216-L217
88+ it ( "returns null with unknown protocols" , ( ) => {
89+ let clean = sanitizeGitRemote (
90+ "git+http://un:p%40sswrd@github.com/apollographql/test"
91+ ) ;
92+ expect ( clean ) . toBeNull ( ) ;
93+ } ) ;
94+ } ) ;
0 commit comments