示例#1
0
// The following Test functions are run in order - this one must come before the others!
func TestAuthenticate(t *testing.T) {
	var err error
	UserName := os.Getenv("SWIFT_API_USER")
	ApiKey := os.Getenv("SWIFT_API_KEY")
	AuthUrl := os.Getenv("SWIFT_AUTH_URL")
	if UserName == "" || ApiKey == "" || AuthUrl == "" {
		srv, err = swifttest.NewSwiftServer("localhost")
		if err != nil {
			t.Fatal("Failed to create server", err)
		}
		UserName = "******"
		ApiKey = "swifttest"
		AuthUrl = srv.AuthURL
	}
	c = swift.Connection{
		UserName: UserName,
		ApiKey:   ApiKey,
		AuthUrl:  AuthUrl,
		Tenant:   os.Getenv("SWIFT_TENANT"),
		TenantId: os.Getenv("SWIFT_TENANT_ID"),
	}
	err = c.Authenticate()
	if err != nil {
		t.Fatal("Auth failed", err)
	}
	if !c.Authenticated() {
		t.Fatal("Not authenticated")
	}
}
示例#2
0
func makeConnection() (*swift.Connection, error) {
	var err error

	UserName := os.Getenv("SWIFT_API_USER")
	ApiKey := os.Getenv("SWIFT_API_KEY")
	AuthUrl := os.Getenv("SWIFT_AUTH_URL")

	Insecure := os.Getenv("SWIFT_AUTH_INSECURE")
	ConnectionChannelTimeout := os.Getenv("SWIFT_CONNECTION_CHANNEL_TIMEOUT")
	DataChannelTimeout := os.Getenv("SWIFT_DATA_CHANNEL_TIMEOUT")

	if UserName == "" || ApiKey == "" || AuthUrl == "" {
		if srv != nil {
			srv.Close()
		}
		srv, err = swifttest.NewSwiftServer("localhost")
		if err != nil {
			return nil, err
		}

		UserName = "******"
		ApiKey = "swifttest"
		AuthUrl = srv.AuthURL
	}

	transport := &http.Transport{
		Proxy:               http.ProxyFromEnvironment,
		MaxIdleConnsPerHost: 2048,
	}
	if Insecure == "1" {
		transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
	}

	c := swift.Connection{
		UserName:       UserName,
		ApiKey:         ApiKey,
		AuthUrl:        AuthUrl,
		Transport:      transport,
		ConnectTimeout: 60 * time.Second,
		Timeout:        60 * time.Second,
	}

	var timeout int64
	if ConnectionChannelTimeout != "" {
		timeout, err = strconv.ParseInt(ConnectionChannelTimeout, 10, 32)
		if err == nil {
			c.ConnectTimeout = time.Duration(timeout) * time.Second
		}
	}

	if DataChannelTimeout != "" {
		timeout, err = strconv.ParseInt(DataChannelTimeout, 10, 32)
		if err == nil {
			c.Timeout = time.Duration(timeout) * time.Second
		}
	}

	return &c, nil
}
示例#3
0
func (s *PublishedStorageSuite) SetUpTest(c *C) {
	var err error

	rand.Seed(int64(time.Now().Nanosecond()))

	s.TestAddress = fmt.Sprintf("localhost:%d", rand.Intn(10000)+20000)
	s.AuthURL = "http://" + s.TestAddress + "/v1.0"

	s.srv, err = swifttest.NewSwiftServer(s.TestAddress)
	c.Assert(err, IsNil)
	c.Assert(s.srv, NotNil)

	s.storage, err = NewPublishedStorage("swifttest", "swifttest", s.AuthURL, "", "", "", "", "", "", "test", "")
	c.Assert(err, IsNil)

	s.prefixedStorage, err = NewPublishedStorage("swifttest", "swifttest", s.AuthURL, "", "", "", "", "", "", "test", "lala")
	c.Assert(err, IsNil)

	s.storage.conn.ContainerCreate("test", nil)
}
示例#4
0
func TestTransport(t *testing.T) {
	var err error
	UserName := os.Getenv("SWIFT_API_USER")
	ApiKey := os.Getenv("SWIFT_API_KEY")
	AuthUrl := os.Getenv("SWIFT_AUTH_URL")
	if UserName == "" || ApiKey == "" || AuthUrl == "" {
		srv, err = swifttest.NewSwiftServer("localhost")
		if err != nil {
			t.Fatal("Failed to create server", err)
		}
		UserName = "******"
		ApiKey = "swifttest"
		AuthUrl = srv.AuthURL
	}
	tr := &someTransport{Transport: http.Transport{MaxIdleConnsPerHost: 2048}}
	ct := swift.Connection{
		UserName:       UserName,
		ApiKey:         ApiKey,
		AuthUrl:        AuthUrl,
		Tenant:         os.Getenv("SWIFT_TENANT"),
		TenantId:       os.Getenv("SWIFT_TENANT_ID"),
		Transport:      tr,
		ConnectTimeout: 60 * time.Second,
		Timeout:        60 * time.Second,
	}
	err = ct.Authenticate()
	if err != nil {
		t.Fatal("Auth failed", err)
	}
	if !ct.Authenticated() {
		t.Fatal("Not authenticated")
	}
	if srv != nil {
		srv.Close()
	}
}
示例#5
0
func init() {
	var (
		username           string
		password           string
		authURL            string
		tenant             string
		tenantID           string
		domain             string
		domainID           string
		container          string
		region             string
		insecureSkipVerify bool
		swiftServer        *swifttest.SwiftServer
		err                error
	)
	username = os.Getenv("SWIFT_USERNAME")
	password = os.Getenv("SWIFT_PASSWORD")
	authURL = os.Getenv("SWIFT_AUTH_URL")
	tenant = os.Getenv("SWIFT_TENANT_NAME")
	tenantID = os.Getenv("SWIFT_TENANT_ID")
	domain = os.Getenv("SWIFT_DOMAIN_NAME")
	domainID = os.Getenv("SWIFT_DOMAIN_ID")
	container = os.Getenv("SWIFT_CONTAINER_NAME")
	region = os.Getenv("SWIFT_REGION_NAME")
	insecureSkipVerify, _ = strconv.ParseBool(os.Getenv("SWIFT_INSECURESKIPVERIFY"))

	if username == "" || password == "" || authURL == "" || container == "" {
		if swiftServer, err = swifttest.NewSwiftServer("localhost"); err != nil {
			panic(err)
		}
		username = "******"
		password = "******"
		authURL = swiftServer.AuthURL
		container = "test"
	}

	prefix, err := ioutil.TempDir("", "driver-")
	if err != nil {
		panic(err)
	}
	defer os.Remove(prefix)

	swiftDriverConstructor = func(root string) (*Driver, error) {
		parameters := Parameters{
			username,
			password,
			authURL,
			tenant,
			tenantID,
			domain,
			domainID,
			region,
			container,
			root,
			insecureSkipVerify,
			defaultChunkSize,
		}

		return New(parameters)
	}

	driverConstructor := func() (storagedriver.StorageDriver, error) {
		return swiftDriverConstructor(prefix)
	}

	testsuites.RegisterSuite(driverConstructor, testsuites.NeverSkip)
}
示例#6
0
func init() {
	var (
		username           string
		password           string
		authURL            string
		tenant             string
		tenantID           string
		domain             string
		domainID           string
		container          string
		region             string
		prefix             string
		insecureSkipVerify bool
		swiftServer        *swifttest.SwiftServer
		err                error
	)
	if username = os.Getenv("OS_USERNAME"); username == "" {
		username = os.Getenv("ST_USER")
	}
	if password = os.Getenv("OS_PASSWORD"); password == "" {
		password = os.Getenv("ST_KEY")
	}
	if authURL = os.Getenv("OS_AUTH_URL"); authURL == "" {
		authURL = os.Getenv("ST_AUTH")
	}
	tenant = os.Getenv("OS_TENANT_NAME")
	tenantID = os.Getenv("OS_TENANT_ID")
	domain = os.Getenv("OS_DOMAIN_NAME")
	domainID = os.Getenv("OS_DOMAIN_ID")
	container = os.Getenv("OS_CONTAINER_NAME")
	region = os.Getenv("OS_REGION_NAME")
	prefix = os.Getenv("OS_CONTAINER_PREFIX")
	insecureSkipVerify, _ = strconv.ParseBool(os.Getenv("ST_INSECURESKIPVERIFY"))

	if username == "" || password == "" || authURL == "" || container == "" {
		if swiftServer, err = swifttest.NewSwiftServer("localhost"); err != nil {
			panic(err)
		}
		username = "******"
		password = "******"
		authURL = swiftServer.AuthURL
		container = "test"
	}

	root, err := ioutil.TempDir("", "driver-")
	if err != nil {
		panic(err)
	}
	defer os.Remove(root)

	swiftDriverConstructor := func(rootDirectory string) (*Driver, error) {
		parameters := DriverParameters{
			username,
			password,
			authURL,
			tenant,
			tenantID,
			domain,
			domainID,
			region,
			container,
			prefix,
			insecureSkipVerify,
			defaultChunkSize,
		}

		return New(parameters)
	}

	skipCheck := func() string {
		return ""
	}

	driverConstructor := func() (storagedriver.StorageDriver, error) {
		return swiftDriverConstructor(root)
	}

	testsuites.RegisterInProcessSuite(driverConstructor, skipCheck)

	RegisterSwiftDriverSuite(swiftDriverConstructor, skipCheck, swiftServer)
}
示例#7
0
func init() {
	var (
		username           string
		password           string
		authURL            string
		tenant             string
		tenantID           string
		domain             string
		domainID           string
		tenantDomain       string
		tenantDomainID     string
		trustID            string
		container          string
		region             string
		AuthVersion        int
		endpointType       string
		insecureSkipVerify bool
		secretKey          string
		accessKey          string
		containerKey       bool
		tempURLMethods     []string

		swiftServer *swifttest.SwiftServer
		err         error
	)
	username = os.Getenv("SWIFT_USERNAME")
	password = os.Getenv("SWIFT_PASSWORD")
	authURL = os.Getenv("SWIFT_AUTH_URL")
	tenant = os.Getenv("SWIFT_TENANT_NAME")
	tenantID = os.Getenv("SWIFT_TENANT_ID")
	domain = os.Getenv("SWIFT_DOMAIN_NAME")
	domainID = os.Getenv("SWIFT_DOMAIN_ID")
	tenantDomain = os.Getenv("SWIFT_DOMAIN_NAME")
	tenantDomainID = os.Getenv("SWIFT_DOMAIN_ID")
	trustID = os.Getenv("SWIFT_TRUST_ID")
	container = os.Getenv("SWIFT_CONTAINER_NAME")
	region = os.Getenv("SWIFT_REGION_NAME")
	AuthVersion, _ = strconv.Atoi(os.Getenv("SWIFT_AUTH_VERSION"))
	endpointType = os.Getenv("SWIFT_ENDPOINT_TYPE")
	insecureSkipVerify, _ = strconv.ParseBool(os.Getenv("SWIFT_INSECURESKIPVERIFY"))
	secretKey = os.Getenv("SWIFT_SECRET_KEY")
	accessKey = os.Getenv("SWIFT_ACCESS_KEY")
	containerKey, _ = strconv.ParseBool(os.Getenv("SWIFT_TEMPURL_CONTAINERKEY"))
	tempURLMethods = strings.Split(os.Getenv("SWIFT_TEMPURL_METHODS"), ",")

	if username == "" || password == "" || authURL == "" || container == "" {
		if swiftServer, err = swifttest.NewSwiftServer("localhost"); err != nil {
			panic(err)
		}
		username = "******"
		password = "******"
		authURL = swiftServer.AuthURL
		container = "test"
	}

	prefix, err := ioutil.TempDir("", "driver-")
	if err != nil {
		panic(err)
	}
	defer os.Remove(prefix)

	swiftDriverConstructor = func(root string) (*Driver, error) {
		parameters := Parameters{
			username,
			password,
			authURL,
			tenant,
			tenantID,
			domain,
			domainID,
			tenantDomain,
			tenantDomainID,
			trustID,
			region,
			AuthVersion,
			container,
			root,
			endpointType,
			insecureSkipVerify,
			defaultChunkSize,
			secretKey,
			accessKey,
			containerKey,
			tempURLMethods,
		}

		return New(parameters)
	}

	driverConstructor := func() (storagedriver.StorageDriver, error) {
		return swiftDriverConstructor(prefix)
	}

	testsuites.RegisterSuite(driverConstructor, testsuites.NeverSkip)
}