// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 package localdb import ( "database/sql" "git.arvados.org/arvados.git/lib/ctrlctx" "git.arvados.org/arvados.git/sdk/go/arvados" "git.arvados.org/arvados.git/sdk/go/arvadostest" check "gopkg.in/check.v1" ) var _ = check.Suite(&TestUserSuite{}) type TestUserSuite struct { localdbSuite } func (s *TestUserSuite) SetUpTest(c *check.C) { s.localdbSuite.SetUpTest(c) s.cluster.Login.Test.Enable = true s.cluster.Login.Test.Users = map[string]arvados.TestUser{ "valid": {Email: "valid@example.com", Password: "v@l1d"}, } s.localdb.loginController = &testLoginController{ Cluster: s.cluster, Parent: s.localdb, } } func (s *TestUserSuite) TestLogin(c *check.C) { for _, trial := range []struct { success bool username string password string }{ {false, "foo", "bar"}, {false, "", ""}, {false, "valid", ""}, {false, "", "v@l1d"}, {true, "valid", "v@l1d"}, {true, "valid@example.com", "v@l1d"}, } { c.Logf("=== %#v", trial) resp, err := s.localdb.UserAuthenticate(s.ctx, arvados.UserAuthenticateOptions{ Username: trial.username, Password: trial.password, }) if trial.success { c.Check(err, check.IsNil) c.Check(resp.APIToken, check.Not(check.Equals), "") c.Check(resp.UUID, check.Matches, `zzzzz-gj3su-.*`) c.Check(resp.Scopes, check.DeepEquals, []string{"all"}) authinfo := getCallbackAuthInfo(c, s.railsSpy) c.Check(authinfo.Email, check.Equals, "valid@example.com") c.Check(authinfo.AlternateEmails, check.DeepEquals, []string(nil)) } else { c.Check(err, check.ErrorMatches, `authentication failed.*`) } } } func (s *TestUserSuite) TestLoginForm(c *check.C) { resp, err := s.localdb.Login(s.ctx, arvados.LoginOptions{ ReturnTo: "https://localhost:12345/example", }) c.Check(err, check.IsNil) c.Check(resp.HTML.String(), check.Matches, `(?ms).*