Add support to ban users from creating sessions
This commit is contained in:
@@ -77,6 +77,43 @@ func TestSessionNew(t *testing.T) {
|
||||
_e.M.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestSessionFailWhenUserIsBanned(t *testing.T) {
|
||||
config.PWDContainerName = "pwd"
|
||||
|
||||
_d := &docker.Mock{}
|
||||
_f := &docker.FactoryMock{}
|
||||
_s := &storage.Mock{}
|
||||
_g := &id.MockGenerator{}
|
||||
_e := &event.Mock{}
|
||||
|
||||
ipf := provisioner.NewInstanceProvisionerFactory(provisioner.NewWindowsASG(_f, _s), provisioner.NewDinD(_g, _f, _s))
|
||||
sp := provisioner.NewOverlaySessionProvisioner(_f)
|
||||
|
||||
_g.On("NewId").Return("aaaabbbbcccc")
|
||||
_f.On("GetForSession", mock.AnythingOfType("*types.Session")).Return(_d, nil)
|
||||
_d.On("NetworkCreate", "aaaabbbbcccc", dtypes.NetworkCreate{Attachable: true, Driver: "overlay"}).Return(nil)
|
||||
_d.On("DaemonHost").Return("localhost")
|
||||
_d.On("NetworkConnect", config.L2ContainerName, "aaaabbbbcccc", "").Return("10.0.0.1", nil)
|
||||
_s.On("SessionPut", mock.AnythingOfType("*types.Session")).Return(nil)
|
||||
_s.On("UserGet", mock.Anything).Return(&types.User{IsBanned: true}, nil)
|
||||
_s.On("SessionCount").Return(1, nil)
|
||||
_s.On("InstanceCount").Return(0, nil)
|
||||
_s.On("ClientCount").Return(0, nil)
|
||||
|
||||
var nilArgs []interface{}
|
||||
_e.M.On("Emit", event.SESSION_NEW, "aaaabbbbcccc", nilArgs).Return()
|
||||
|
||||
p := NewPWD(_f, _e, _s, sp, ipf)
|
||||
p.generator = _g
|
||||
|
||||
playground := &types.Playground{Id: "foobar"}
|
||||
sConfig := types.SessionConfig{Playground: playground, UserId: "", Duration: time.Hour, Stack: "", StackName: "", ImageName: ""}
|
||||
s, e := p.SessionNew(context.Background(), sConfig)
|
||||
assert.NotNil(t, e)
|
||||
assert.Nil(t, s)
|
||||
assert.Contains(t, e.Error(), "banned")
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
************************** Not sure how to test this as it can pick any manager as the first node in the swarm cluster.
|
||||
|
||||
Reference in New Issue
Block a user