예제 #1
0
파일: test.go 프로젝트: aaithal/empire
// NewServer builds a new empire.Empire instance and returns an httptest.Server
// running the empire API.
func NewServer(t testing.TB, e *empire.Empire) *httptest.Server {
	if e == nil {
		e = NewEmpire(t)
	}

	return httptest.NewServer(server.New(e, server.DefaultOptions))
}
예제 #2
0
파일: server.go 프로젝트: iserko/empire
func newServer(c *Context, e *empire.Empire) http.Handler {
	var opts server.Options
	opts.GitHub.Webhooks.Secret = c.String(FlagGithubWebhooksSecret)
	opts.GitHub.Deployments.Environments = strings.Split(c.String(FlagGithubDeploymentsEnvironments), ",")
	opts.GitHub.Deployments.ImageBuilder = newImageBuilder(c)
	opts.GitHub.Deployments.TugboatURL = c.String(FlagGithubDeploymentsTugboatURL)

	s := server.New(e, opts)
	s.URL = c.URL(FlagURL)
	s.Heroku.Auth = newAuth(c, e)
	s.Heroku.Secret = []byte(c.String(FlagSecret))

	sp, err := c.SAMLServiceProvider()
	if err != nil {
		panic(err)
	}

	if sp != nil {
		s.ServiceProvider = sp
		s.Heroku.Unauthorized = heroku.SAMLUnauthorized(c.String(FlagURL) + "/saml/login")
	}

	h := middleware.Common(s)
	return middleware.Handler(c, h)
}
예제 #3
0
파일: server.go 프로젝트: aaithal/empire
func newServer(c *cli.Context, e *empire.Empire) http.Handler {
	opts := server.Options{}
	opts.GitHub.ClientID = c.String(FlagGithubClient)
	opts.GitHub.ClientSecret = c.String(FlagGithubSecret)
	opts.GitHub.Organization = c.String(FlagGithubOrg)
	opts.GitHub.ApiURL = c.String(FlagGithubApiURL)

	return server.New(e, opts)
}
예제 #4
0
파일: test.go 프로젝트: no2key/empire
// NewServer builds a new empire.Empire instance and returns an httptest.Server
// running the empire API.
func NewServer(t testing.TB, e *empire.Empire) *httptest.Server {
	if e == nil {
		e = NewEmpire(t)
	}

	server.DefaultOptions.GitHub.Webhooks.Secret = "abcd"
	server.DefaultOptions.GitHub.Deployments.Environment = "test"
	return httptest.NewServer(server.New(e, server.DefaultOptions))
}
예제 #5
0
파일: test.go 프로젝트: frewsxcv/empire
// NewServer builds a new empire.Empire instance and returns an httptest.Server
// running the empire API.
func NewServer(t testing.TB, e *empire.Empire) *httptest.Server {
	if e == nil {
		e = NewEmpire(t)
	}

	server.DefaultOptions.GitHub.Webhooks.Secret = "abcd"
	server.DefaultOptions.GitHub.Deployments.Environment = "test"
	server.DefaultOptions.Authenticator = auth.Anyone(&empire.User{Name: "fake"})
	return httptest.NewServer(server.New(e, server.DefaultOptions))
}
예제 #6
0
파일: server.go 프로젝트: is00hcw/empire
func newServer(c *cli.Context, e *empire.Empire) http.Handler {
	var opts server.Options
	opts.Authenticator = newAuthenticator(c, e)
	opts.GitHub.Webhooks.Secret = c.String(FlagGithubWebhooksSecret)
	opts.GitHub.Deployments.Environments = strings.Split(c.String(FlagGithubDeploymentsEnvironments), ",")
	opts.GitHub.Deployments.ImageBuilder = newImageBuilder(c)
	opts.GitHub.Deployments.TugboatURL = c.String(FlagGithubDeploymentsTugboatURL)

	return server.New(e, opts)
}
예제 #7
0
파일: test.go 프로젝트: brianz/empire
// NewTestServer returns a new httptest.Server for testing empire's http server.
func NewTestServer(t testing.TB, e *empire.Empire, opts server.Options) *Server {
	if e == nil {
		e = NewEmpire(t)
	}

	s := server.New(e, opts)
	return &Server{
		Empire: e,
		Server: httptest.NewServer(middleware.Handler(context.Background(), s)),
	}
}
예제 #8
0
파일: test.go 프로젝트: is00hcw/empire
// NewServer builds a new empire.Empire instance and returns an httptest.Server
// running the empire API.
func NewServer(t testing.TB, e *empire.Empire) *httptest.Server {
	if e == nil {
		e = NewEmpire(t)
	}

	server.DefaultOptions.GitHub.Webhooks.Secret = "abcd"
	server.DefaultOptions.Authenticator = auth.Anyone(&empire.User{Name: "fake"})
	server.DefaultOptions.GitHub.Deployments.Environments = []string{"test"}
	server.DefaultOptions.GitHub.Deployments.ImageBuilder = github.ImageFromTemplate(template.Must(template.New("image").Parse(github.DefaultTemplate)))
	return httptest.NewServer(server.New(e, server.DefaultOptions))
}
예제 #9
0
파일: server.go 프로젝트: galvezz/empire
func newServer(c *cli.Context, e *empire.Empire) http.Handler {
	opts := server.Options{}
	opts.GitHub.ClientID = c.String(FlagGithubClient)
	opts.GitHub.ClientSecret = c.String(FlagGithubClientSecret)
	opts.GitHub.Organization = c.String(FlagGithubOrg)
	opts.GitHub.ApiURL = c.String(FlagGithubApiURL)
	opts.GitHub.Webhooks.Secret = c.String(FlagGithubWebhooksSecret)
	opts.GitHub.Deployments.Environment = c.String(FlagGithubDeploymentsEnvironment)
	opts.GitHub.Deployments.ImageTemplate = c.String(FlagGithubDeploymentsImageTemplate)
	opts.GitHub.Deployments.TugboatURL = c.String(FlagGithubDeploymentsTugboatURL)

	return server.New(e, opts)
}
예제 #10
0
파일: server.go 프로젝트: brianz/empire
func newServer(c *cli.Context, e *empire.Empire) (http.Handler, error) {
	rootCtx, err := newRootContext(c)
	if err != nil {
		return nil, err
	}

	var opts server.Options
	opts.Authenticator = newAuthenticator(c, e)
	opts.GitHub.Webhooks.Secret = c.String(FlagGithubWebhooksSecret)
	opts.GitHub.Deployments.Environments = strings.Split(c.String(FlagGithubDeploymentsEnvironments), ",")
	opts.GitHub.Deployments.ImageBuilder = newImageBuilder(c)
	opts.GitHub.Deployments.TugboatURL = c.String(FlagGithubDeploymentsTugboatURL)

	h := middleware.Common(server.New(e, opts))
	return middleware.Handler(rootCtx, h), nil
}
예제 #11
0
파일: test.go 프로젝트: iserko/empire
// newTestServer returns a new httptest.Server for testing empire's http server.
func newTestServer(t testing.TB, e *empire.Empire, opts server.Options) *Server {
	if e == nil {
		e = NewEmpire(t)
	}

	// Log reporter errors to stderr
	ctx := reporter.WithReporter(context.Background(), reporter.ReporterFunc(func(ctx context.Context, err error) error {
		fmt.Fprintf(os.Stderr, "reported error: %v\n", err)
		return nil
	}))

	s := server.New(e, opts)
	svr := httptest.NewUnstartedServer(middleware.Handler(ctx, s))
	u, _ := url.Parse(svr.URL)
	s.URL = u
	return &Server{
		Empire: e,
		Server: s,
		svr:    svr,
	}
}
예제 #12
0
func TestLoginTwoFactor(t *testing.T) {
	e := empiretest.NewEmpire(t)
	s := httptest.NewServer(server.New(e, server.Options{
		Authenticator: auth.StaticAuthenticator("twofactor", "bar", "code", &empire.User{Name: "fake"}),
	}))
	defer s.Close()

	input := "twofactor\nbar\ncode\n"

	cmd := NewCmd(s.URL, "login")
	cmd.Stdin = strings.NewReader(input)

	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatal(err)
	}

	if got, want := string(out), "Enter email: Enter two-factor auth code: Logged in.\n"; got != want {
		t.Fatalf("%q", got)
	}
}
예제 #13
0
func TestLoginUnauthorized(t *testing.T) {
	e := empiretest.NewEmpire(t)
	s := httptest.NewServer(server.New(e, server.Options{
		Authenticator: auth.StaticAuthenticator("fake", "bar", "", &empire.User{Name: "fake"}),
	}))
	defer s.Close()

	input := "foo\nbar\n"

	cmd := NewCmd(s.URL, "login")
	cmd.Stdin = strings.NewReader(input)

	out, err := cmd.CombinedOutput()
	if err == nil {
		t.Fatal("Expected an error")
	}

	if got, want := string(out), "Enter email: error: Request not authenticated, API token is missing, invalid or expired Log in with `emp login`.\n"; got != want {
		t.Fatalf("%q", got)
	}
}