Example #1
0
func (s *CharmSuite) SetUpTest(c *gc.C) {
	s.Server = charmstoretesting.OpenServer(c, s.jcSuite.Session, charmstore.ServerParams{
		AuthUsername: "******",
		AuthPassword: "******",
	})
	urls := []string{
		"~who/quantal/mysql-23",
		"~who/quantal/dummy-24",
		"~who/quantal/riak-25",
		"~who/quantal/wordpress-26",
		"~who/quantal/logging-27",
	}
	for _, url := range urls {
		id := charm.MustParseReference(url)
		ch := testcharms.Repo.CharmArchive(c.MkDir(), id.Name)
		s.Server.UploadCharm(c, ch, id, true)
	}
	s.jcSuite.PatchValue(&charmrepo.CacheDir, c.MkDir())
	// Patch the charm repo initializer function: it is replaced with a charm
	// store repo pointing to the testing server.
	s.jcSuite.PatchValue(&charmrevisionupdater.NewCharmStore, func(p charmrepo.NewCharmStoreParams) charmrepo.Interface {
		p.URL = s.Server.URL()
		return charmrepo.NewCharmStore(p)
	})
	s.charms = make(map[string]*state.Charm)
}
Example #2
0
func (s *UpgradeCharmErrorsSuite) SetUpTest(c *gc.C) {
	s.RepoSuite.SetUpTest(c)
	s.srv = charmstoretesting.OpenServer(c, s.Session, charmstore.ServerParams{})
	s.PatchValue(&charmrepo.CacheDir, c.MkDir())
	original := newCharmStoreClient
	s.PatchValue(&newCharmStoreClient, func() (*csClient, error) {
		csclient, err := original()
		c.Assert(err, jc.ErrorIsNil)
		csclient.params.URL = s.srv.URL()
		return csclient, nil
	})
}
Example #3
0
func (s *charmStoreSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)

	// Set up the third party discharger.
	s.discharger = bakerytest.NewDischarger(nil, func(req *http.Request, cond string, arg string) ([]checkers.Caveat, error) {
		cookie, err := req.Cookie(clientUserCookie)
		if err != nil {
			return nil, errors.New("discharge denied to non-clients")
		}
		return []checkers.Caveat{
			checkers.DeclaredCaveat("username", cookie.Value),
		}, nil
	})

	// Set up the charm store testing server.
	s.srv = charmstoretesting.OpenServer(c, s.Session, charmstore.ServerParams{
		IdentityLocation: s.discharger.Location(),
		PublicKeyLocator: s.discharger,
	})

	// Initialize the charm cache dir.
	s.PatchValue(&charmrepo.CacheDir, c.MkDir())

	// Point the CLI to the charm store testing server.
	original := newCharmStoreClient
	s.PatchValue(&newCharmStoreClient, func() (*csClient, error) {
		csclient, err := original()
		if err != nil {
			return nil, err
		}
		csclient.params.URL = s.srv.URL()
		// Add a cookie so that the discharger can detect whether the
		// HTTP client is the juju environment or the juju client.
		lurl, err := url.Parse(s.discharger.Location())
		if err != nil {
			panic(err)
		}
		csclient.params.HTTPClient.Jar.SetCookies(lurl, []*http.Cookie{{
			Name:  clientUserCookie,
			Value: clientUserName,
		}})
		return csclient, nil
	})

	// Point the Juju API server to the charm store testing server.
	s.PatchValue(&csclient.ServerURL, s.srv.URL())
}
Example #4
0
func (s *CharmStoreSuite) SetUpTest(c *gc.C) {
	s.CleanupSuite.SetUpTest(c)

	s.discharger = bakerytest.NewDischarger(nil, func(_ *http.Request, cond string, arg string) ([]checkers.Caveat, error) {
		if s.DischargeUser == "" {
			return nil, fmt.Errorf("discharge denied")
		}
		return []checkers.Caveat{
			checkers.DeclaredCaveat("username", s.DischargeUser),
		}, nil
	})
	s.Srv = charmstoretesting.OpenServer(c, s.Session, charmstore.ServerParams{
		IdentityLocation: s.discharger.Location(),
		PublicKeyLocator: s.discharger,
	})
	s.PatchValue(&charmrepo.CacheDir, c.MkDir())
	s.PatchValue(&service.NewCharmStore, func(p charmrepo.NewCharmStoreParams) charmrepo.Interface {
		p.URL = s.Srv.URL()
		return charmrepo.NewCharmStore(p)
	})
}