This commit is contained in:
Ian Gulliver
2023-05-15 21:49:59 -07:00
parent 595f329b3f
commit d337e46f99
4 changed files with 6 additions and 163 deletions

View File

@@ -1,150 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>header: Go Coverage Report</title>
<style>
body {
background: black;
color: rgb(80, 80, 80);
}
body, pre, #legend span {
font-family: Menlo, monospace;
font-weight: bold;
}
#topbar {
background: black;
position: fixed;
top: 0; left: 0; right: 0;
height: 42px;
border-bottom: 1px solid rgb(80, 80, 80);
}
#content {
margin-top: 50px;
}
#nav, #legend {
float: left;
margin-left: 10px;
}
#legend {
margin-top: 12px;
}
#nav {
margin-top: 10px;
}
#legend span {
margin: 0 5px;
}
.cov0 { color: rgb(192, 0, 0) }
.cov1 { color: rgb(128, 128, 128) }
.cov2 { color: rgb(116, 140, 131) }
.cov3 { color: rgb(104, 152, 134) }
.cov4 { color: rgb(92, 164, 137) }
.cov5 { color: rgb(80, 176, 140) }
.cov6 { color: rgb(68, 188, 143) }
.cov7 { color: rgb(56, 200, 146) }
.cov8 { color: rgb(44, 212, 149) }
.cov9 { color: rgb(32, 224, 152) }
.cov10 { color: rgb(20, 236, 155) }
</style>
</head>
<body>
<div id="topbar">
<div id="nav">
<select id="files">
<option value="file0">github.com/gopatchy/header/authorization.go (71.4%)</option>
</select>
</div>
<div id="legend">
<span>not tracked</span>
<span class="cov0">no coverage</span>
<span class="cov1">low coverage</span>
<span class="cov2">*</span>
<span class="cov3">*</span>
<span class="cov4">*</span>
<span class="cov5">*</span>
<span class="cov6">*</span>
<span class="cov7">*</span>
<span class="cov8">*</span>
<span class="cov9">*</span>
<span class="cov10">high coverage</span>
</div>
</div>
<div id="content">
<pre class="file" id="file0" style="display: none">package header
import (
"encoding/base64"
"net/http"
"strings"
"github.com/gopatchy/jsrest"
)
func ParseAuthorization(r *http.Request) (string, string) <span class="cov10" title="2">{
auth := r.Header.Get("Authorization")
if auth == "" </span><span class="cov0" title="0">{
return "", ""
}</span>
<span class="cov10" title="2">parts := strings.Split(auth, " ")
if len(parts) != 2 </span><span class="cov0" title="0">{
return "", ""
}</span>
<span class="cov10" title="2">return parts[0], parts[1]</span>
}
func ParseBasic(val string) (string, string, error) <span class="cov1" title="1">{
raw, err := base64.StdEncoding.DecodeString(val)
if err != nil </span><span class="cov0" title="0">{
return "", "", jsrest.Errorf(jsrest.ErrBadRequest, "Authorization header Basic data base64 decode failed (%w)", err)
}</span>
<span class="cov1" title="1">parts := strings.SplitN(string(raw), ":", 2)
if len(parts) != 2 </span><span class="cov0" title="0">{
return "", "", jsrest.Errorf(jsrest.ErrBadRequest, "Authorization header Basic data malformed")
}</span>
<span class="cov1" title="1">return parts[0], parts[1], nil</span>
}
</pre>
</div>
</body>
<script>
(function() {
var files = document.getElementById('files');
var visible;
files.addEventListener('change', onChange, false);
function select(part) {
if (visible)
visible.style.display = 'none';
visible = document.getElementById(part);
if (!visible)
return;
files.value = part;
visible.style.display = 'block';
location.hash = part;
}
function onChange() {
select(files.value);
window.scrollTo(0, 0);
}
if (location.hash != "") {
select(location.hash.substr(1));
}
if (!visible) {
select("file0");
}
})();
</script>
</html>

View File

@@ -1,11 +0,0 @@
mode: atomic
github.com/gopatchy/header/authorization.go:11.59,14.16 2 2
github.com/gopatchy/header/authorization.go:14.16,16.3 1 0
github.com/gopatchy/header/authorization.go:18.2,19.21 2 2
github.com/gopatchy/header/authorization.go:19.21,21.3 1 0
github.com/gopatchy/header/authorization.go:23.2,23.27 1 2
github.com/gopatchy/header/authorization.go:26.53,28.16 2 1
github.com/gopatchy/header/authorization.go:28.16,30.3 1 0
github.com/gopatchy/header/authorization.go:32.2,33.21 2 1
github.com/gopatchy/header/authorization.go:33.21,35.3 1 0
github.com/gopatchy/header/authorization.go:37.2,37.32 1 1

4
go.mod
View File

@@ -3,14 +3,14 @@ module github.com/gopatchy/header
go 1.19
require (
github.com/gopatchy/jsrest v0.0.0-20230516044821-deb630cd744b
github.com/gopatchy/jsrest v0.0.0-20230516044950-1c6d15dad16a
github.com/stretchr/testify v1.8.2
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/gopatchy/metadata v0.0.0-20230516041300-fc49e5f775fe // indirect
github.com/gopatchy/metadata v0.0.0-20230516044939-eed23a0903d5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/vfaronov/httpheader v0.1.0 // indirect
golang.org/x/net v0.10.0 // indirect

4
go.sum
View File

@@ -9,10 +9,14 @@ github.com/gopatchy/jsrest v0.0.0-20230516041300-629b5ec41627 h1:3jV2PPVVTOGI1D2
github.com/gopatchy/jsrest v0.0.0-20230516041300-629b5ec41627/go.mod h1:77Kp7hFjygVlnDH48qO917da0gyKNR2XG8mZtaAEL9w=
github.com/gopatchy/jsrest v0.0.0-20230516044821-deb630cd744b h1:fnoLhs0kk7rc/hdk1vn8lzJ9uiq1ANr3klSUwbze1ys=
github.com/gopatchy/jsrest v0.0.0-20230516044821-deb630cd744b/go.mod h1:MQBtK0M/Uota4CpW5NbsjDqWuoQyYjS70PJSxWf3nLE=
github.com/gopatchy/jsrest v0.0.0-20230516044950-1c6d15dad16a h1:ehV4YITvldTIuTMAq7kk0RcrBE7m3WQKFzFl/jOqh7w=
github.com/gopatchy/jsrest v0.0.0-20230516044950-1c6d15dad16a/go.mod h1:TVfwj+gk7iCGJRrVYR+0ovXhOc90UXPrBCOGPLE8Fsw=
github.com/gopatchy/metadata v0.0.0-20230424223338-33e58fee42bf h1:HKCbhVEpC3++ydeapSJN2DGs9KGWMvOLpcZrwKkrXQs=
github.com/gopatchy/metadata v0.0.0-20230424223338-33e58fee42bf/go.mod h1:VgD33raUShjDePCDBo55aj+eSXFtUEpMzs+Ie39g2zo=
github.com/gopatchy/metadata v0.0.0-20230516041300-fc49e5f775fe h1:xPnlis/qCAYoxHx9tow1P4pO17c8JH/Hs/lHDmZej/Q=
github.com/gopatchy/metadata v0.0.0-20230516041300-fc49e5f775fe/go.mod h1:VgD33raUShjDePCDBo55aj+eSXFtUEpMzs+Ie39g2zo=
github.com/gopatchy/metadata v0.0.0-20230516044939-eed23a0903d5 h1:b66b4DOGTqDuw4hbxHSp0WbhXr/xAMaiFkU6iCi4nDg=
github.com/gopatchy/metadata v0.0.0-20230516044939-eed23a0903d5/go.mod h1:VgD33raUShjDePCDBo55aj+eSXFtUEpMzs+Ie39g2zo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=