From 82e67d82546631e6c51a088484fa92cc59f9fcce Mon Sep 17 00:00:00 2001 From: Hector Date: Tue, 20 Jun 2023 22:32:33 +0100 Subject: [PATCH] remove old auth code --- cfg/basicAuth.go | 25 ------------------ cfg/basicAuth_test.go | 60 ------------------------------------------- 2 files changed, 85 deletions(-) delete mode 100644 cfg/basicAuth.go delete mode 100644 cfg/basicAuth_test.go diff --git a/cfg/basicAuth.go b/cfg/basicAuth.go deleted file mode 100644 index 991861e..0000000 --- a/cfg/basicAuth.go +++ /dev/null @@ -1,25 +0,0 @@ -package cfg - -import "gitlab.com/hectorjsmith/fail2ban-prometheus-exporter/auth" - -type hashedBasicAuth struct { - username string - password string -} - -func newHashedBasicAuth(rawUsername, rawPassword string) *hashedBasicAuth { - return &hashedBasicAuth{ - username: auth.HashString(rawUsername), - password: auth.HashString(rawPassword), - } -} - -func (p *hashedBasicAuth) Enabled() bool { - return len(p.username) > 0 && len(p.password) > 0 -} - -func (p *hashedBasicAuth) DoesBasicAuthMatch(rawUsername, rawPassword string) bool { - username := auth.HashString(rawUsername) - password := auth.HashString(rawPassword) - return username == p.username && password == p.password -} diff --git a/cfg/basicAuth_test.go b/cfg/basicAuth_test.go deleted file mode 100644 index 85bd8b3..0000000 --- a/cfg/basicAuth_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package cfg - -import "testing" - -func Test_hashedBasicAuth_DoesBasicAuthMatch(t *testing.T) { - type args struct { - username string - password string - } - type fields struct { - username string - password string - } - tests := []struct { - name string - fields fields - args args - want bool - }{ - {"Happy test #1", fields{username: "1234", password: "1234"}, args{username: "1234", password: "1234"}, true}, - {"Happy test #2", fields{username: "test", password: "1234"}, args{username: "test", password: "1234"}, true}, - {"Happy test #3", fields{username: "TEST", password: "1234"}, args{username: "TEST", password: "1234"}, true}, - {"Non match #1", fields{username: "test", password: "1234"}, args{username: "1234", password: "1234"}, false}, - {"Non match #2", fields{username: "1234", password: "test"}, args{username: "1234", password: "1234"}, false}, - {"Non match #3", fields{username: "1234", password: "test"}, args{username: "1234", password: "TEST"}, false}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - basicAuth := newHashedBasicAuth(tt.fields.username, tt.fields.password) - if got := basicAuth.DoesBasicAuthMatch(tt.args.username, tt.args.password); got != tt.want { - t.Errorf("DoesBasicAuthMatch() = %v, want %v", got, tt.want) - } - }) - } -} - -func Test_hashedBasicAuth_Enabled(t *testing.T) { - type fields struct { - username string - password string - } - tests := []struct { - name string - fields fields - want bool - }{ - {"Both blank", fields{username: "", password: ""}, false}, - {"Single blank #1", fields{username: "test", password: ""}, false}, - {"Single blank #1", fields{username: "", password: "test"}, false}, - {"Both populated", fields{username: "test", password: "test"}, true}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - basicAuth := newHashedBasicAuth(tt.fields.username, tt.fields.password) - if got := basicAuth.Enabled(); got != tt.want { - t.Errorf("Enabled() = %v, want %v", got, tt.want) - } - }) - } -}