1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.arvados.org/arvados.git/lib/boot"
16 "git.arvados.org/arvados.git/lib/config"
17 "git.arvados.org/arvados.git/lib/controller/rpc"
18 "git.arvados.org/arvados.git/lib/service"
19 "git.arvados.org/arvados.git/sdk/go/arvados"
20 "git.arvados.org/arvados.git/sdk/go/arvadosclient"
21 "git.arvados.org/arvados.git/sdk/go/auth"
22 "git.arvados.org/arvados.git/sdk/go/ctxlog"
23 "git.arvados.org/arvados.git/sdk/go/keepclient"
24 check "gopkg.in/check.v1"
27 var _ = check.Suite(&IntegrationSuite{})
29 type testCluster struct {
32 controllerURL *url.URL
35 type IntegrationSuite struct {
36 testClusters map[string]*testCluster
39 func (s *IntegrationSuite) SetUpSuite(c *check.C) {
41 c.Skip("heavy integration tests don't run with forceLegacyAPI14")
46 s.testClusters = map[string]*testCluster{
51 hostport := map[string]string{}
52 for id := range s.testClusters {
53 hostport[id] = func() string {
54 // TODO: Instead of expecting random ports on
55 // 127.0.0.11, 22, 33 to be race-safe, try
56 // different 127.x.y.z until finding one that
58 ln, err := net.Listen("tcp", ":0")
59 c.Assert(err, check.IsNil)
61 _, port, err := net.SplitHostPort(ln.Addr().String())
62 c.Assert(err, check.IsNil)
63 return "127.0.0." + id[3:] + ":" + port
66 for id := range s.testClusters {
71 ExternalURL: https://` + hostport[id] + `
80 Host: ` + hostport["z1111"] + `
86 Host: ` + hostport["z2222"] + `
92 Host: ` + hostport["z3333"] + `
98 loader := config.NewLoader(bytes.NewBufferString(yaml), ctxlog.TestLogger(c))
100 loader.SkipLegacy = true
101 loader.SkipAPICalls = true
102 cfg, err := loader.Load()
103 c.Assert(err, check.IsNil)
104 s.testClusters[id] = &testCluster{
106 SourcePath: filepath.Join(cwd, "..", ".."),
107 LibPath: filepath.Join(cwd, "..", "..", "tmp"),
109 ListenHost: "127.0.0." + id[3:],
110 ControllerAddr: ":0",
111 OwnTemporaryDatabase: true,
112 Stderr: &service.LogPrefixer{Writer: ctxlog.LogWriter(c.Log), Prefix: []byte("[" + id + "] ")},
116 s.testClusters[id].booter.Start(context.Background(), &s.testClusters[id].config)
118 for _, tc := range s.testClusters {
119 au, ok := tc.booter.WaitReady()
120 c.Assert(ok, check.Equals, true)
122 tc.controllerURL = &u
126 func (s *IntegrationSuite) TearDownSuite(c *check.C) {
127 for _, c := range s.testClusters {
132 func (s *IntegrationSuite) conn(clusterID string) *rpc.Conn {
133 return rpc.NewConn(clusterID, s.testClusters[clusterID].controllerURL, true, rpc.PassthroughTokenProvider)
136 func (s *IntegrationSuite) clientsWithToken(clusterID string, token string) (context.Context, *arvados.Client, *keepclient.KeepClient) {
137 cl := s.testClusters[clusterID].config.Clusters[clusterID]
138 ctx := auth.NewContext(context.Background(), auth.NewCredentials(token))
139 ac, err := arvados.NewClientFromConfig(&cl)
144 arv, err := arvadosclient.New(ac)
148 kc := keepclient.New(arv)
152 func (s *IntegrationSuite) userClients(c *check.C, conn *rpc.Conn, rootctx context.Context, clusterID string, activate bool) (context.Context, *arvados.Client, *keepclient.KeepClient) {
153 login, err := conn.UserSessionCreate(rootctx, rpc.UserSessionCreateOptions{
154 ReturnTo: ",https://example.com",
155 AuthInfo: rpc.UserSessionAuthInfo{
156 Email: "user@example.com",
157 FirstName: "Example",
162 c.Assert(err, check.IsNil)
163 redirURL, err := url.Parse(login.RedirectLocation)
164 c.Assert(err, check.IsNil)
165 userToken := redirURL.Query().Get("api_token")
166 c.Logf("userToken: %q", userToken)
167 ctx, ac, kc := s.clientsWithToken(clusterID, userToken)
168 user, err := conn.UserGetCurrent(ctx, arvados.GetOptions{})
172 _, err = conn.UserSetup(rootctx, arvados.UserSetupOptions{UUID: user.UUID})
176 _, err = conn.UserActivate(rootctx, arvados.UserActivateOptions{UUID: user.UUID})
180 user, err = conn.UserGetCurrent(ctx, arvados.GetOptions{})
184 c.Logf("user: %#v", user)
186 c.Fatal("failed to activate user")
191 func (s *IntegrationSuite) rootClients(clusterID string) (context.Context, *arvados.Client, *keepclient.KeepClient) {
192 return s.clientsWithToken(clusterID, s.testClusters[clusterID].config.Clusters[clusterID].SystemRootToken)
195 func (s *IntegrationSuite) TestLoopDetection(c *check.C) {
196 conn1 := s.conn("z1111")
197 rootctx1, _, _ := s.rootClients("z1111")
198 conn3 := s.conn("z3333")
199 // rootctx3, _, _ := s.rootClients("z3333")
201 userctx1, ac1, kc1 := s.userClients(c, conn1, rootctx1, "z1111", true)
202 _, err := conn1.CollectionGet(userctx1, arvados.GetOptions{UUID: "1f4b0bc7583c2a7f9102c395f4ffc5e3+45"})
203 c.Assert(err, check.ErrorMatches, `.*404 Not Found.*`)
205 var coll1 arvados.Collection
206 fs1, err := coll1.FileSystem(ac1, kc1)
210 f, err := fs1.OpenFile("foo", os.O_CREATE|os.O_RDWR, 0777)
211 f.Write([]byte("foo"))
213 mtxt, err := fs1.MarshalManifest(".")
214 coll1, err = conn1.CollectionCreate(userctx1, arvados.CreateOptions{Attrs: map[string]interface{}{
215 "manifest_text": mtxt,
217 c.Assert(err, check.IsNil)
218 coll, err := conn3.CollectionGet(userctx1, arvados.GetOptions{UUID: "1f4b0bc7583c2a7f9102c395f4ffc5e3+45"})
219 c.Check(err, check.IsNil)
220 c.Check(coll.PortableDataHash, check.Equals, "1f4b0bc7583c2a7f9102c395f4ffc5e3+45")