This repository has been archived by the owner on Mar 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Genki Sugawara
committed
Jun 12, 2016
1 parent
beae871
commit cfc9ccb
Showing
37 changed files
with
3,574 additions
and
699 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
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,28 @@ | ||
package gcredstash | ||
|
||
import ( | ||
"encoding/base64" | ||
) | ||
|
||
func B64Decode(encoded string) []byte { | ||
decoded, err := base64.StdEncoding.DecodeString(encoded) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return decoded | ||
} | ||
|
||
func B64DecodeStr(encoded string) string { | ||
decoded := B64Decode(encoded) | ||
return string(decoded) | ||
} | ||
|
||
func B64Encode(decoded []byte) string { | ||
return base64.StdEncoding.EncodeToString(decoded) | ||
} | ||
|
||
func B64EncodeStr(decoded string) string { | ||
return B64Encode([]byte(decoded)) | ||
} |
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,24 @@ | ||
package gcredstash | ||
|
||
import ( | ||
. "gcredstash" | ||
"testing" | ||
) | ||
|
||
func TestB64DecodeStr(t *testing.T) { | ||
expected := "London Bridge is broken down" | ||
actual := B64DecodeStr("TG9uZG9uIEJyaWRnZSBpcyBicm9rZW4gZG93bg==") | ||
|
||
if expected != actual { | ||
t.Errorf("\nexpected: %v\ngot: %v\n", expected, actual) | ||
} | ||
} | ||
|
||
func TestB64EncodeStr(t *testing.T) { | ||
expected := "TG9uZG9uIEJyaWRnZSBpcyBicm9rZW4gZG93bg==" | ||
actual := B64EncodeStr("London Bridge is broken down") | ||
|
||
if expected != actual { | ||
t.Errorf("\nexpected: %v\ngot: %v\n", expected, actual) | ||
} | ||
} |
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,67 @@ | ||
package command | ||
|
||
import ( | ||
"gcredstash" | ||
. "gcredstash/command" | ||
"gcredstash/testutils" | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/dynamodb" | ||
"github.com/golang/mock/gomock" | ||
"mockaws" | ||
"testing" | ||
) | ||
|
||
func TestDeleteCommand(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
mddb := mockaws.NewMockDynamoDBAPI(ctrl) | ||
mkms := mockaws.NewMockKMSAPI(ctrl) | ||
table := "credential-store" | ||
name := "test.key" | ||
version := "0000000000000000002" | ||
|
||
item := map[string]string{ | ||
"contents": "eBtO1lgLxIe6Yw==", | ||
"hmac": "b23a3efafd4795e50ca87afd7d764f263e9ae456499a8d40eece70a63ed5da27", | ||
"key": "CiDY1vsR456LEdoL3+0p+PrTCleoqi/sutbDfJZNiUSpphLLAQEBAQB42Nb7EeOeixHaC9/tKfj60wpXqKov7LrWw3yWTYlEqaYAAACiMIGfBgkqhkiG9w0BBwaggZEwgY4CAQAwgYgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMy/Oc2pOJsR0y9nbhAgEQgFsHECqku7QZiRjLmmeGyhcsgWdWvi7Op3luJu4soi5sP0pqcsjTrBJqOXHLazgyBS9wb6deP8zpXa/41WT0ZpNY9at4gw7+XRtbz8f4Rlh8WnyFnK5RZ7i0mOlD", | ||
"name": name, | ||
"version": version, | ||
} | ||
|
||
mddb.EXPECT().Query(&dynamodb.QueryInput{ | ||
TableName: aws.String(table), | ||
ConsistentRead: aws.Bool(true), | ||
KeyConditionExpression: aws.String("#name = :name"), | ||
ExpressionAttributeNames: map[string]*string{"#name": aws.String("name")}, | ||
ExpressionAttributeValues: map[string]*dynamodb.AttributeValue{ | ||
":name": {S: aws.String(name)}, | ||
}, | ||
}).Return(&dynamodb.QueryOutput{ | ||
Count: aws.Int64(1), | ||
Items: []map[string]*dynamodb.AttributeValue{testutils.MapToItem(item)}, | ||
}, nil) | ||
|
||
mddb.EXPECT().DeleteItem(&dynamodb.DeleteItemInput{ | ||
TableName: aws.String(table), | ||
Key: map[string]*dynamodb.AttributeValue{ | ||
"name": {S: aws.String(name)}, | ||
"version": {S: aws.String(version)}, | ||
}, | ||
}).Return(nil, nil) | ||
|
||
cmd := &DeleteCommand{ | ||
Meta: Meta{ | ||
Table: table, | ||
KmsKey: "alias/credstash", | ||
Driver: &gcredstash.Driver{Ddb: mddb, Kms: mkms}, | ||
}, | ||
} | ||
|
||
args := []string{name} | ||
err := cmd.RunImpl(args) | ||
|
||
if err != nil { | ||
t.Errorf("\nexpected: %v\ngot: %v\n", nil, err) | ||
} | ||
} |
Oops, something went wrong.