mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 08:21:11 +00:00 
			
		
		
		
	[GITEA] add option for banning dots in usernames
Refs: https://codeberg.org/forgejo/forgejo/pulls/676 Author: Panagiotis "Ivory" Vasilopoulos <git@n0toose.net> Date: Mon Jun 12 13:57:01 2023 +0200 Co-authored-by: Gusted <postmaster@gusted.xyz> (cherry picked from commitfabdda5c6e) (cherry picked from commitd2c7f45621) (cherry picked from commitdfdbaba3d6)
This commit is contained in:
		
					parent
					
						
							
								66e1d3f082
							
						
					
				
			
			
				commit
				
					
						a3cda092b8
					
				
			
		
					 7 changed files with 57 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -155,7 +155,8 @@ func Test_IsValidExternalTrackerURLFormat(t *testing.T) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestIsValidUsername(t *testing.T) {
 | 
			
		||||
func TestIsValidUsernameAllowDots(t *testing.T) {
 | 
			
		||||
	setting.Service.AllowDotsInUsernames = true
 | 
			
		||||
	tests := []struct {
 | 
			
		||||
		arg  string
 | 
			
		||||
		want bool
 | 
			
		||||
| 
						 | 
				
			
			@ -185,3 +186,31 @@ func TestIsValidUsername(t *testing.T) {
 | 
			
		|||
		})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestIsValidUsernameBanDots(t *testing.T) {
 | 
			
		||||
	setting.Service.AllowDotsInUsernames = false
 | 
			
		||||
	defer func() {
 | 
			
		||||
		setting.Service.AllowDotsInUsernames = true
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	tests := []struct {
 | 
			
		||||
		arg  string
 | 
			
		||||
		want bool
 | 
			
		||||
	}{
 | 
			
		||||
		{arg: "a", want: true},
 | 
			
		||||
		{arg: "abc", want: true},
 | 
			
		||||
		{arg: "0.b-c", want: false},
 | 
			
		||||
		{arg: "a.b-c_d", want: false},
 | 
			
		||||
		{arg: ".abc", want: false},
 | 
			
		||||
		{arg: "abc.", want: false},
 | 
			
		||||
		{arg: "a..bc", want: false},
 | 
			
		||||
		{arg: "a...bc", want: false},
 | 
			
		||||
		{arg: "a.-bc", want: false},
 | 
			
		||||
		{arg: "a._bc", want: false},
 | 
			
		||||
	}
 | 
			
		||||
	for _, tt := range tests {
 | 
			
		||||
		t.Run(tt.arg, func(t *testing.T) {
 | 
			
		||||
			assert.Equalf(t, tt.want, IsValidUsername(tt.arg), "IsValidUsername[AllowDotsInUsernames=false](%v)", tt.arg)
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue