Skip to content

Commit 9a98863

Browse files
committed
Fixed minor issues reported by golint and go vet
1 parent 6ceed8f commit 9a98863

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

csrf.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Synchronizer Token Pattern implementation.
1+
// Package csrf is a synchronizer Token Pattern implementation.
22
//
33
// See [OWASP] https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet
44
package csrf
@@ -24,6 +24,7 @@ var (
2424
safeMethods = regexp.MustCompile("^(GET|HEAD|OPTIONS|TRACE|WS)$")
2525
)
2626

27+
// CSRFFilter implements the CSRF filter.
2728
var CSRFFilter = func(c *revel.Controller, fc []revel.Filter) {
2829
r := c.Request.Request
2930

exemptions.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package csrf is a synchronizer Token Pattern implementation.
2+
//
13
// Management of routes exempted from CSRF checks.
24
package csrf
35

@@ -26,7 +28,7 @@ var (
2628
exemptionsGlobs globPath
2729
)
2830

29-
// Checks if given path is exempt from CSRF checks.
31+
// IsExempted checks whether given path is exempt from CSRF checks or not.
3032
func IsExempted(path string) bool {
3133
exemptionsFullPath.RLock()
3234
_, found := exemptionsFullPath.list[path]
@@ -52,21 +54,22 @@ func IsExempted(path string) bool {
5254
return false
5355
}
5456

55-
// Exempts an exact path from CSRF checks.
57+
// ExemptedFullPath exempts one exact path from CSRF checks.
5658
func ExemptedFullPath(path string) {
5759
glog.V(2).Infof("REVEL-CSRF: Adding exemption '%s'...", path)
5860
exemptionsFullPath.Lock()
5961
exemptionsFullPath.list[path] = struct{}{}
6062
exemptionsFullPath.Unlock()
6163
}
6264

65+
// ExemptedFullPath exempts exact paths from CSRF checks.
6366
func ExemptedFullPaths(paths ...string) {
6467
for _, v := range paths {
6568
ExemptedFullPath(v)
6669
}
6770
}
6871

69-
// Exempts a path from CSRF checks using pattern matching.
72+
// ExemptedGlob exempts one path from CSRF checks using pattern matching.
7073
// See http://golang.org/pkg/path/#Match
7174
func ExemptedGlob(path string) {
7275
glog.V(2).Infof("REVEL-CSRF: Adding exemption GLOB '%s'...", path)
@@ -75,6 +78,7 @@ func ExemptedGlob(path string) {
7578
exemptionsGlobs.Unlock()
7679
}
7780

81+
// ExemptedGlobs exempts paths from CSRF checks using pattern matching.
7882
func ExemptedGlobs(paths ...string) {
7983
for _, v := range paths {
8084
ExemptedGlob(v)

exemptions_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
)
66

77
func TestExemptedFullPath(t *testing.T) {
8-
//hand := New(nil)
98
path := "/Hello"
109

1110
ExemptedFullPath(path)
@@ -20,25 +19,22 @@ func TestExemptedFullPath(t *testing.T) {
2019
}
2120

2221
func TestExemptedFullPaths(t *testing.T) {
23-
//hand := New(nil)
2422
paths := []string{"/home", "/news", "/help"}
25-
ExemptedFullPaths(paths...)
2623

24+
ExemptedFullPaths(paths...)
2725
for _, v := range paths {
2826
if !IsExempted(v) {
2927
t.Errorf("%v should be exempted, but it isn't", v)
3028
}
3129
}
3230

3331
other := "/accounts"
34-
3532
if IsExempted(other) {
36-
t.Errorf("%v is exempted, but it shouldn't be")
33+
t.Errorf("%v is exempted, but it shouldn't be", other)
3734
}
3835
}
3936

4037
func TestExemptedGlob(t *testing.T) {
41-
//hand := New(nil)
4238
glob := "/[m-n]ail"
4339

4440
ExemptedGlob(glob)
@@ -67,25 +63,23 @@ func TestExemptedGlob(t *testing.T) {
6763
func TestExemptedGlobs(t *testing.T) {
6864
slice := []string{"/", "/accounts/*", "/post/?*"}
6965
matching := []string{"/", "/accounts/", "/accounts/johndoe", "/post/1", "/post/123"}
70-
7166
nonMatching := []string{"", "/accounts",
7267
// Glob's * and ? don't match a forward slash.
7368
"/accounts/johndoe/posts",
7469
"/post/",
7570
}
7671

77-
//hand := New(nil)
7872
ExemptedGlobs(slice...)
7973

8074
for _, v := range matching {
8175
if !IsExempted(v) {
82-
t.Error("%v should be exempted, but it isn't.")
76+
t.Errorf("%v should be exempted, but it isn't.", v)
8377
}
8478
}
8579

8680
for _, v := range nonMatching {
8781
if IsExempted(v) {
88-
t.Error("%v shouldn't be exempted, but it is")
82+
t.Errorf("%v shouldn't be exempted, but it is", v)
8983
}
9084
}
9185
}

0 commit comments

Comments
 (0)