@@ -24,22 +24,18 @@ describe('renderer/routes/gitea/LoginWithPersonalAccessToken.tsx', () => {
2424 expect ( tree . container ) . toMatchSnapshot ( ) ;
2525 } ) ;
2626
27- describe ( 'form validation' , ( ) => {
28- it . each ( [ 'gitea.example.com' , 'gitea.example.com:3000' , 'forgejo.example.com:443' ] ) (
29- 'accepts %s' ,
30- ( hostname ) => {
31- expect (
32- validateForm (
33- {
34- hostname : hostname as Hostname ,
35- token : 'abcdef1234567890abcdef1234567890abcdef12' as Token ,
36- } ,
37- 'gitea' ,
38- ) ,
39- ) . toEqual ( { } ) ;
40- } ,
27+ it ( 'disables token settings and rejects credentials or paths in the origin' , async ( ) => {
28+ renderWithProviders ( < GiteaLoginWithPersonalAccessTokenRoute /> ) ;
29+ await userEvent . type (
30+ screen . getByTestId ( 'login-hostname' ) ,
31+ 'http://user:secret@git.internal/path' ,
4132 ) ;
33+ expect ( screen . getByTestId ( 'login-create-token' ) ) . toBeDisabled ( ) ;
34+ await userEvent . click ( screen . getByTestId ( 'login-submit' ) ) ;
35+ expect ( screen . getByText ( 'Hostname format is invalid' ) ) . toBeInTheDocument ( ) ;
36+ } ) ;
4237
38+ describe ( 'form validation' , ( ) => {
4339 it . each ( [ 'gitea.example.com:0' , 'gitea.example.com:65536' , 'gitea.example.com:https' ] ) (
4440 'rejects invalid port in %s' ,
4541 ( hostname ) => {
@@ -67,6 +63,24 @@ describe('renderer/routes/gitea/LoginWithPersonalAccessToken.tsx', () => {
6763 ) . toBe ( 'Hostname format is invalid' ) ;
6864 } ) ;
6965
66+ it . each ( [ 'http://git.internal' , 'http://git.internal:3000' , 'gitea.example.com:3000' ] ) (
67+ 'accepts Gitea origin %s' ,
68+ ( hostname ) => {
69+ expect (
70+ validateForm ( { hostname : hostname as Hostname , token : 'a' . repeat ( 40 ) as Token } , 'gitea' ) ,
71+ ) . toEqual ( { } ) ;
72+ } ,
73+ ) ;
74+
75+ it . each < Forge > ( [ 'github' , 'gitlab' , 'bitbucket' ] ) ( 'keeps %s hostnames HTTPS-only' , ( forge ) => {
76+ expect (
77+ validateForm (
78+ { hostname : 'http://git.internal:3000' as Hostname , token : '' as Token } ,
79+ forge ,
80+ ) . hostname ,
81+ ) . toBe ( 'Hostname format is invalid' ) ;
82+ } ) ;
83+
7084 it ( 'should validate the token matches the Gitea format' , ( ) => {
7185 const values : IFormData = {
7286 hostname : 'gitea.example.com' as Hostname ,
@@ -86,26 +100,25 @@ describe('renderer/routes/gitea/LoginWithPersonalAccessToken.tsx', () => {
86100 } ) ;
87101 } ) ;
88102
89- it . each ( [ 'gitea.example.com' , 'gitea.example.com:3000' ] ) (
90- 'should open the token settings for %s' ,
91- async ( hostname ) => {
92- renderWithProviders ( < GiteaLoginWithPersonalAccessTokenRoute /> , {
93- loginWithPersonalAccessToken : loginWithPersonalAccessTokenMock ,
94- } ) ;
103+ it . each ( [
104+ [ 'gitea.example.com' , 'https://gitea.example.com' ] ,
105+ [ 'gitea.example.com:3000' , 'https://gitea.example.com:3000' ] ,
106+ [ 'http://git.internal:3000' , 'http://git.internal:3000' ] ,
107+ ] ) ( 'opens token settings for %s' , async ( hostname , origin ) => {
108+ renderWithProviders ( < GiteaLoginWithPersonalAccessTokenRoute /> , {
109+ loginWithPersonalAccessToken : loginWithPersonalAccessTokenMock ,
110+ } ) ;
95111
96- await userEvent . type ( screen . getByTestId ( 'login-hostname' ) , hostname ) ;
112+ await userEvent . type ( screen . getByTestId ( 'login-hostname' ) , hostname ) ;
97113
98- await userEvent . click ( screen . getByTestId ( 'login-create-token' ) ) ;
114+ await userEvent . click ( screen . getByTestId ( 'login-create-token' ) ) ;
99115
100- expect ( openExternalLinkSpy ) . toHaveBeenCalledTimes ( 1 ) ;
101- expect ( openExternalLinkSpy ) . toHaveBeenCalledWith (
102- `https://${ hostname } /user/settings/applications` ,
103- ) ;
104- } ,
105- ) ;
116+ expect ( openExternalLinkSpy ) . toHaveBeenCalledTimes ( 1 ) ;
117+ expect ( openExternalLinkSpy ) . toHaveBeenCalledWith ( `${ origin } /user/settings/applications` ) ;
118+ } ) ;
106119
107- it . each ( [ 'gitea.example.com' , 'gitea.example.com:3000' ] ) (
108- 'should login using a token on %s' ,
120+ it . each ( [ 'gitea.example.com' , 'gitea.example.com:3000' , 'http://git.internal:3000' ] ) (
121+ 'logs in with %s' ,
109122 async ( hostname ) => {
110123 loginWithPersonalAccessTokenMock . mockResolvedValueOnce ( null ) ;
111124
0 commit comments