-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
1 parent
6de72a8
commit 13c3ae0
Showing
46 changed files
with
19,099 additions
and
0 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,31 @@ | ||
package faillog | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"os" | ||
) | ||
|
||
// Logger emits content to stderr on Close() if caller panics or | ||
// Success(false) is called. | ||
type Logger struct { | ||
success bool | ||
buffer bytes.Buffer | ||
} | ||
|
||
func (f *Logger) Close() error { | ||
if f.success { | ||
return nil | ||
} | ||
|
||
_, err := io.Copy(os.Stderr, &f.buffer) | ||
return err | ||
} | ||
|
||
func (f *Logger) Success(success bool) { | ||
f.success = success | ||
} | ||
|
||
func (f *Logger) Write(p []byte) (n int, err error) { | ||
return f.buffer.Write(p) | ||
} |
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,60 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"github.com/iann0036/iamlive/faillog" | ||
"github.com/stretchr/testify/assert" | ||
"net/http/httptest" | ||
"os" | ||
"os/exec" | ||
"testing" | ||
) | ||
|
||
func TestSimpleRequest(t *testing.T) { | ||
if testing.Short() { | ||
t.Skipf("skipping e2e test") | ||
} | ||
|
||
parseConfig() | ||
flag.Parse() | ||
loadMaps() | ||
readServiceFiles() | ||
*modeFlag = "proxy" | ||
|
||
p := createProxy() | ||
ts := httptest.NewServer(p) | ||
defer ts.Close() | ||
|
||
fl := &faillog.Logger{} | ||
defer fl.Close() | ||
|
||
cmd := exec.Command("aws", "sts", "get-caller-identity") | ||
cmd.Stdout = fl | ||
cmd.Stderr = fl | ||
cmd.Env = append(os.Environ(), | ||
"AWS_CA_BUNDLE=~/.iamlive/ca.pem", | ||
"HTTP_PROXY="+ts.URL, | ||
"HTTPS_PROXY="+ts.URL, | ||
) | ||
|
||
err := cmd.Run() | ||
assert.NoError(t, err) | ||
|
||
doc := getPolicyDocument() | ||
assert.JSONEq(t, ` | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"sts:GetCallerIdentity" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} | ||
`, string(doc)) | ||
|
||
fl.Success(!t.Failed()) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.