示例#1
0
func (s *signedSuite) SetUpSuite(c *gc.C) {
	var imageData = map[string]string{
		"/unsigned/streams/v1/index.json":          unsignedIndex,
		"/unsigned/streams/v1/tools_metadata.json": unsignedProduct,
	}

	// Set up some signed data from the unsigned data.
	// Overwrite the product path to use the sjson suffix.
	rawUnsignedIndex := strings.Replace(
		unsignedIndex, "streams/v1/tools_metadata.json", "streams/v1/tools_metadata.sjson", -1)
	r := bytes.NewReader([]byte(rawUnsignedIndex))
	signedData, err := simplestreams.Encode(
		r, sstesting.SignedMetadataPrivateKey, sstesting.PrivateKeyPassphrase)
	c.Assert(err, jc.ErrorIsNil)
	imageData["/signed/streams/v1/index.sjson"] = string(signedData)

	// Replace the tools path in the unsigned data with a different one so we can test that the right
	// tools path is used.
	rawUnsignedProduct := strings.Replace(
		unsignedProduct, "juju-1.13.0", "juju-1.13.1", -1)
	r = bytes.NewReader([]byte(rawUnsignedProduct))
	signedData, err = simplestreams.Encode(
		r, sstesting.SignedMetadataPrivateKey, sstesting.PrivateKeyPassphrase)
	c.Assert(err, jc.ErrorIsNil)
	imageData["/signed/streams/v1/tools_metadata.sjson"] = string(signedData)
	testRoundTripper.Sub = jujutest.NewCannedRoundTripper(
		imageData, map[string]int{"signedtest://unauth": http.StatusUnauthorized})
	s.origKey = tools.SetSigningPublicKey(sstesting.SignedMetadataPublicKey)
}
示例#2
0
// Set Metadata requests to be served by the filecontent supplied.
func UseExternalTestImageMetadata(creds *auth.Credentials) {
	metadata := parseIndexData(creds)
	files := map[string]string{
		"/streams/v1/index.json":                            metadata.String(),
		"/streams/v1/com.ubuntu.cloud:released:joyent.json": imagesData,
	}
	testRoundTripper.Sub = jujutest.NewCannedRoundTripper(files, nil)
	imagemetadata.DefaultBaseURL = "test://host"
}
// useTestImageData causes the given content to be served when published metadata is requested.
func useTestImageData(files map[string]string) {
	if files != nil {
		testRoundTripper.Sub = jujutest.NewCannedRoundTripper(files, nil)
		imagemetadata.DefaultBaseURL = "test:"
	} else {
		testRoundTripper.Sub = nil
		imagemetadata.DefaultBaseURL = ""
	}
}
示例#4
0
func useTestImageData(files map[string]string) {
	if files != nil {
		testRoundTripper.Sub = &CountingRoundTripper{
			CannedRoundTripper: jujutest.NewCannedRoundTripper(files, nil),
		}
	} else {
		testRoundTripper.Sub = nil
	}
}
示例#5
0
// UseTestImageData causes the given content to be served
// when the ec2 client asks for image data.
func UseTestImageData(files map[string]string) {
	if files != nil {
		testRoundTripper.Sub = jujutest.NewCannedRoundTripper(files, nil)
		imagemetadata.DefaultBaseURL = "test:"
		signedImageDataOnly = false
	} else {
		signedImageDataOnly = true
		testRoundTripper.Sub = nil
		imagemetadata.DefaultBaseURL = origImagesUrl
	}
}
示例#6
0
func (s *providerSuite) makeTestMetadata(c *gc.C, series, location string, im []*imagemetadata.ImageMetadata) {
	cloudSpec := simplestreams.CloudSpec{
		Region:   location,
		Endpoint: "https://management.core.windows.net/",
	}

	seriesVersion, err := version.SeriesVersion(series)
	c.Assert(err, jc.ErrorIsNil)
	for _, im := range im {
		im.Version = seriesVersion
		im.RegionName = cloudSpec.Region
		im.Endpoint = cloudSpec.Endpoint
	}

	index, products, err := imagemetadata.MarshalImageMetadataJSON(
		im, []simplestreams.CloudSpec{cloudSpec}, time.Now(),
	)
	c.Assert(err, jc.ErrorIsNil)
	files := map[string]string{
		"/streams/v1/index.json":                string(index),
		"/" + imagemetadata.ProductMetadataPath: string(products),
	}
	s.PatchValue(&testRoundTripper.Sub, jujutest.NewCannedRoundTripper(files, nil))
}
示例#7
0
// RegisterMachinesEndpoint creates a fake endpoint so that
// machines api calls succeed.
func RegisterMachinesEndpoint() {
	files := map[string]string{
		"/test/machines": "",
	}
	testRoundTripper.Sub = jujutest.NewCannedRoundTripper(files, nil)
}
示例#8
0
文件: testing.go 项目: rogpeppe/juju
func (s *TestDataSuite) SetUpSuite(c *gc.C) {
	testRoundTripper.Sub = jujutest.NewCannedRoundTripper(
		imageData, map[string]int{"test://unauth": http.StatusUnauthorized})
}