forked from rusq/slackdump
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rusq#98 from rusq/creds-store
Credentials encryption and storage
- Loading branch information
Showing
34 changed files
with
1,706 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/go/.devcontainer/base.Dockerfile | ||
|
||
# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.18, 1.17, 1-bullseye, 1.18-bullseye, 1.17-bullseye, 1-buster, 1.18-buster, 1.17-buster | ||
ARG VARIANT="1.18-bullseye" | ||
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT} | ||
|
||
# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 | ||
ARG NODE_VERSION="none" | ||
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi | ||
|
||
# [Optional] Uncomment this section to install additional OS packages. | ||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
# && apt-get -y install --no-install-recommends <your-package-list-here> | ||
|
||
# [Optional] Uncomment the next lines to use go get to install anything else you need | ||
# USER vscode | ||
# RUN go get -x <your-dependency-or-tool> | ||
|
||
# [Optional] Uncomment this line to install global node packages. | ||
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ secrets.* | |
cmd/slackdump/slackdump | ||
cmd/sdconv/sdconv | ||
/slackdump | ||
/TODO.* | ||
/*.txt | ||
*~ | ||
.env | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM golang:1.18.4 | ||
|
||
WORKDIR /build | ||
|
||
COPY . . | ||
|
||
|
||
RUN go test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package auth | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"net/http" | ||
"reflect" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestLoad(t *testing.T) { | ||
type args struct { | ||
r io.Reader | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want ValueAuth | ||
wantErr bool | ||
}{ | ||
{ | ||
"loads valid data", | ||
args{strings.NewReader(`{"Token":"token_value","Cookie":[{"Name":"d","Value":"abc","Path":"","Domain":"","Expires":"0001-01-01T00:00:00Z","RawExpires":"","MaxAge":0,"Secure":false,"HttpOnly":false,"SameSite":0,"Raw":"","Unparsed":null}]}`)}, | ||
ValueAuth{simpleProvider{Token: "token_value", Cookie: []http.Cookie{ | ||
{Name: "d", Value: "abc"}, | ||
}}}, | ||
false, | ||
}, | ||
{ | ||
"corrupt data", | ||
args{strings.NewReader(`{`)}, | ||
ValueAuth{}, | ||
true, | ||
}, | ||
{ | ||
"no data", | ||
args{strings.NewReader(``)}, | ||
ValueAuth{}, | ||
true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := Load(tt.args.r) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("Load() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("Load() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSave(t *testing.T) { | ||
type args struct { | ||
p Provider | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantW string | ||
wantErr bool | ||
}{ | ||
{ | ||
"all info present", | ||
args{ValueAuth{simpleProvider{Token: "token_value", Cookie: []http.Cookie{ | ||
{Name: "d", Value: "abc"}, | ||
}}}}, | ||
`{"Token":"token_value","Cookie":[{"Name":"d","Value":"abc","Path":"","Domain":"","Expires":"0001-01-01T00:00:00Z","RawExpires":"","MaxAge":0,"Secure":false,"HttpOnly":false,"SameSite":0,"Raw":"","Unparsed":null}]}` + "\n", | ||
false, | ||
}, | ||
{ | ||
"token missing", | ||
args{ValueAuth{simpleProvider{Token: "", Cookie: []http.Cookie{ | ||
{Name: "d", Value: "abc"}, | ||
}}}}, | ||
"", | ||
true, | ||
}, | ||
{ | ||
"cookies missing", | ||
args{ValueAuth{simpleProvider{Token: "token_value", Cookie: []http.Cookie{}}}}, | ||
"", | ||
true, | ||
}, | ||
{ | ||
"token and cookie are missing", | ||
args{ValueAuth{simpleProvider{}}}, | ||
"", | ||
true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
w := &bytes.Buffer{} | ||
if err := Save(w, tt.args.p); (err != nil) != tt.wantErr { | ||
t.Errorf("Save() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
gotW := w.String() | ||
if gotW != tt.wantW { | ||
t.Errorf("Save() = %v, want %v", gotW, tt.wantW) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.