Exemple #1
0
func TestMemcachedPresentSingleHost(t *testing.T) {
	if len(memcachedHosts) == 0 {
		t.Skip("Skipping memcached tests")
	}
	p, err := NewMemcachedProvider(memcachedHosts[0:1])
	assert.NoError(t, err)

	challengePath := path.Join("/", acme.HTTP01ChallengePath(token))

	err = p.Present(domain, token, keyAuth)
	assert.NoError(t, err)
	mc, err := memcache.New(memcachedHosts[0])
	assert.NoError(t, err)
	i, err := mc.Get(challengePath)
	assert.NoError(t, err)
	assert.Equal(t, i.Value, []byte(keyAuth))
}
Exemple #2
0
func memcacheOpener(url *config.URL) (driver.Driver, error) {
	hosts := strings.Split(url.Value, ",")
	conns := make([]string, len(hosts))
	for ii, v := range hosts {
		conns[ii] = driver.DefaultPort(v, 11211)
	}
	client, err := memcache.New(conns...)
	if err != nil {
		return nil, err
	}
	if tm, ok := url.Fragment.Int("timeout"); ok {
		client.SetTimeout(time.Millisecond * time.Duration(tm))
	}
	if maxIdle, ok := url.Fragment.Int("max_idle"); ok {
		client.SetMaxIdleConnsPerAddr(maxIdle)
	}
	return &memcacheDriver{Client: client}, nil
}
Exemple #3
0
func TestMemcachedPresentMultiHost(t *testing.T) {
	if len(memcachedHosts) <= 1 {
		t.Skip("Skipping memcached multi-host tests")
	}
	p, err := NewMemcachedProvider(memcachedHosts)
	assert.NoError(t, err)

	challengePath := path.Join("/", acme.HTTP01ChallengePath(token))

	err = p.Present(domain, token, keyAuth)
	assert.NoError(t, err)
	for _, host := range memcachedHosts {
		mc, err := memcache.New(host)
		assert.NoError(t, err)
		i, err := mc.Get(challengePath)
		assert.NoError(t, err)
		assert.Equal(t, i.Value, []byte(keyAuth))
	}
}
Exemple #4
0
func deleteKeys(addr string, prefix string) {
	println("Deleting keys (hosts = "+addr, ", prefix = '"+prefix+"')")
	t, err := telnet.Dial("tcp", addr)
	checkErr(err)
	t.SetUnixWriteMode(true)

	slabs := getSlabs(t)
	keys := findKeys(t, slabs, prefix)

	mc, e1 := memcache.New(addr)
	checkErr(e1)

	for i := range keys {
		key := keys[i]
		log.Printf("Removing key: %s", key)

		e2 := mc.Delete(key)
		checkErr(e2)
	}
}
Exemple #5
0
func TestMemcachedPresentPartialFailureMultiHost(t *testing.T) {
	if len(memcachedHosts) == 0 {
		t.Skip("Skipping memcached tests")
	}
	hosts := append(memcachedHosts, "5.5.5.5:11211")
	p, err := NewMemcachedProvider(hosts)
	assert.NoError(t, err)

	challengePath := path.Join("/", acme.HTTP01ChallengePath(token))

	err = p.Present(domain, token, keyAuth)
	assert.NoError(t, err)
	for _, host := range memcachedHosts {
		mc, err := memcache.New(host)
		assert.NoError(t, err)
		i, err := mc.Get(challengePath)
		assert.NoError(t, err)
		assert.Equal(t, i.Value, []byte(keyAuth))
	}
}
Exemple #6
0
// Present makes the token available at `HTTP01ChallengePath(token)` by creating a file in the given webroot path
func (w *MemcachedProvider) Present(domain, token, keyAuth string) error {
	var errs []error

	challengePath := path.Join("/", acme.HTTP01ChallengePath(token))
	for _, host := range w.hosts {
		mc, err := memcache.New(host)
		if err != nil {
			errs = append(errs, err)
			continue
		}
		mc.Add(&memcache.Item{
			Key:        challengePath,
			Value:      []byte(keyAuth),
			Expiration: 60,
		})
	}

	if len(errs) == len(w.hosts) {
		return fmt.Errorf("Unable to store key in any of the memcache hosts -> %v", errs)
	}

	return nil
}