Move logger lib to web-core repo
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
*~
|
||||
*.swp
|
||||
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Write.as
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,3 @@
|
||||
Write.as web core
|
||||
=================
|
||||
[](https://travis-ci.org/writeas/web-core)
|
||||
@@ -0,0 +1,14 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var postReg = regexp.MustCompile("(.*(/|id=))[a-zA-Z0-9]{12,13}(.*)")
|
||||
var tokenReg = regexp.MustCompile("(.*t=)[a-zA-Z0-9]{32}(.*)")
|
||||
|
||||
func ScrubID(uri string) string {
|
||||
curStr := postReg.ReplaceAllString(uri, "$1[scrubbed]$3")
|
||||
curStr = tokenReg.ReplaceAllString(curStr, "$1[scrubbed]$2")
|
||||
return curStr
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type scrubTest struct {
|
||||
Input string
|
||||
Expected string
|
||||
}
|
||||
|
||||
var uris = []scrubTest{
|
||||
scrubTest{Input: "/1234567890123", Expected: "/[scrubbed]"},
|
||||
scrubTest{Input: "/acnsd8ndsklao", Expected: "/[scrubbed]"},
|
||||
scrubTest{Input: "/ACNSD8NDSKLAO", Expected: "/[scrubbed]"},
|
||||
scrubTest{Input: "/acNsD8NdSKlaO", Expected: "/[scrubbed]"},
|
||||
scrubTest{Input: "/acnsd8ndsklao.txt", Expected: "/[scrubbed].txt"},
|
||||
scrubTest{Input: "/8sj2kkjsn192.json", Expected: "/[scrubbed].json"},
|
||||
scrubTest{Input: "/acnsd8Ndsklao", Expected: "/[scrubbed]"},
|
||||
scrubTest{Input: "/12345678901", Expected: "/12345678901"},
|
||||
scrubTest{Input: "GET /8s9dja0vjbklj", Expected: "GET /[scrubbed]"},
|
||||
scrubTest{Input: "POST /8s9dja0vjbklj?delete=true", Expected: "POST /[scrubbed]?delete=true"},
|
||||
scrubTest{Input: "GET /8s9dja0vjbkl", Expected: "GET /[scrubbed]"},
|
||||
scrubTest{Input: "GET /asdf90as.txt", Expected: "GET /asdf90as.txt"},
|
||||
scrubTest{Input: "GET /api/999999999999", Expected: "GET /api/[scrubbed]"},
|
||||
scrubTest{Input: "DELETE /api/?id=8s9dja0vjbkl&t=123456789012345678901234567890ab", Expected: "DELETE /api/?id=[scrubbed]&t=[scrubbed]"},
|
||||
scrubTest{Input: "DELETE /api/8s9dja0vjbkl?t=123456789012345678901234567890ab", Expected: "DELETE /api/[scrubbed]?t=[scrubbed]"},
|
||||
}
|
||||
|
||||
func TestScrubID(t *testing.T) {
|
||||
var scrubRes string
|
||||
|
||||
for i := range uris {
|
||||
scrubRes = ScrubID(uris[i].Input)
|
||||
if scrubRes != uris[i].Expected {
|
||||
t.Errorf("#%d got %v, expected %v", i, scrubRes, uris[i].Expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user