Skip to content

Commit

Permalink
pin (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
refs authored and labkode committed Nov 18, 2019
1 parent 08634bf commit 4965e0e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/http/interceptors/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ func parseConfig(m map[string]interface{}) (*config, error) {
return c, nil
}

func skip(url string, skipped []string) bool {
for i := range skipped {
if strings.HasPrefix(skipped[i], url) {
// skip evaluates whether a source url is a subpath of base
// i.e: /a/b/c/d/e is a subpath of /a/b/c
func skip(source string, base []string) bool {
for i := range base {
if strings.HasPrefix(source, base[i]) {
return true
}
}
Expand Down
44 changes: 44 additions & 0 deletions internal/http/interceptors/auth/auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2018-2019 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package auth

import "testing"

var skipTests = []struct {
name string
url string
base []string
out bool
}{
{"valid subpath", "/a/b/c/d", []string{"/a/b/"}, true},
{"invalid subpath", "/a/b/c", []string{"/a/b/c/d"}, false},
{"equal values", "/a/b/c", []string{"/a/b/c"}, true},
}

func TestSkip(t *testing.T) {
for _, tt := range skipTests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
r := skip(tt.url, tt.base)
if r != tt.out {
t.Errorf("expected %v, want %v", r, tt.out)
}
})
}
}

0 comments on commit 4965e0e

Please sign in to comment.