-
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 #15 from ueckoken/token-with-white
- Loading branch information
Showing
9 changed files
with
198 additions
and
38 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,13 @@ | ||
工事中です。 | ||
|
||
## リリース方法 | ||
|
||
最新のコミットに対してタグを貼ってください。(自動化したいです) | ||
そしてそのタグをプッシュすると自動的にリリースノートが生成されます。 | ||
Assets として(Win, Mac, Linux) x (x86_64, arm64, i386)のビルド成果物が生成されます。 | ||
また ghcr.io にコンテナイメージがプッシュされます。これは x86_64 と arm64 のみに対応です。 | ||
|
||
```bash | ||
git tag v(SEM_VER) | ||
git push --tags | ||
``` |
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,46 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTotpGenGenerateCode(t *testing.T) { | ||
type testCase struct { | ||
secret string | ||
tokenCode string | ||
wantErr bool | ||
} | ||
testCases := map[string]testCase{ | ||
"with no white": { | ||
secret: "xxxxxxxxxxxxxxxxxxxx", | ||
tokenCode: `000241`, | ||
wantErr: false, | ||
}, | ||
"with internal white": { | ||
secret: "xxxxx xxxxx xxxxx xxxxx", | ||
tokenCode: `000241`, | ||
wantErr: false, | ||
}, | ||
"with internal white and leading, trailing spaces": { | ||
secret: " xxxxx xxxxx xxxxx xxxxx ", | ||
tokenCode: `000241`, | ||
wantErr: false, | ||
}, | ||
} | ||
for k, v := range testCases { | ||
t.Run(k, func(t *testing.T) { | ||
t.Parallel() | ||
tokGen := TotpGen{secret: v.secret} | ||
code, err := tokGen.GenerateCode(time.Time{}) | ||
if v.wantErr { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
assert.Equal(t, v.tokenCode, code) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
FROM gcr.io/distroless/static-debian11:nonroot | ||
COPY discotp / | ||
COPY --chown=nonroot:nonroot discotp / | ||
ENTRYPOINT [ "/discotp" ] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"encoding" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestTotpToksUnmarshalText(t *testing.T) { | ||
type inOut struct { | ||
in []byte | ||
out TotpToks | ||
expectErr bool | ||
} | ||
testCases := map[string]inOut{ | ||
"one input": { | ||
in: []byte(`hoge:xxxxxxxxxxxx`), | ||
out: TotpToks{map[service]totpTok{ | ||
"hoge": `xxxxxxxxxxxx`, | ||
}}, | ||
expectErr: false, | ||
}, | ||
"multi input": { | ||
in: []byte(`hoge:xxxxx,fuga:111111`), | ||
out: TotpToks{map[service]totpTok{ | ||
"hoge": "xxxxx", | ||
"fuga": "111111", | ||
}}, | ||
expectErr: false, | ||
}, | ||
"no token with service name": { | ||
in: []byte(`hoge`), | ||
out: TotpToks{nil}, | ||
expectErr: true, | ||
}, | ||
"no token in last service": { | ||
in: []byte(`hoge:xxxxxxx,fuga`), | ||
out: TotpToks{nil}, | ||
expectErr: true, | ||
}, | ||
"empty input": { | ||
in: []byte(``), | ||
out: TotpToks{m: nil}, | ||
expectErr: true, | ||
}, | ||
"multi input with inner spaces": { | ||
in: []byte(`hoge:xxxxx xxxxx xxxxx, fuga: yyyyy yyyyy yyyyy`), | ||
out: TotpToks{map[service]totpTok{ | ||
"hoge": "xxxxx xxxxx xxxxx", | ||
"fuga": "yyyyy yyyyy yyyyy", | ||
}, | ||
}, | ||
expectErr: false, | ||
}, | ||
} | ||
for k, v := range testCases { | ||
t.Run(k, func(t *testing.T) { | ||
var buf TotpToks | ||
err := buf.UnmarshalText(v.in) | ||
if v.expectErr { | ||
assert.Error(t, err) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
assert.Equal(t, v.out, buf) | ||
}) | ||
} | ||
} | ||
|
||
func TestTotpToksImpl(t *testing.T) { | ||
assert.Implements(t, (*encoding.TextUnmarshaler)(nil), new(TotpToks)) | ||
} |