Commit eb6b96df authored by Loïck Bonniot's avatar Loïck Bonniot

[c] Fix tests

parent c0710b02
...@@ -131,7 +131,7 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) { ...@@ -131,7 +131,7 @@ func (m *SignatureManager) addPeer(user *pAPI.User) (ready bool, err error) {
func (m *SignatureManager) SendReadySign() (signatureUUID string, err error) { func (m *SignatureManager) SendReadySign() (signatureUUID string, err error) {
ctx, cancel := context.WithTimeout(context.Background(), 10 * time.Minute) ctx, cancel := context.WithTimeout(context.Background(), 10 * time.Minute)
defer cancel() defer cancel()
launch, err := m.platform.ReadySign(ctx, &api.ReadySignRequest{ launch, err := m.platform.ReadySign(ctx, &pAPI.ReadySignRequest{
ContractUuid: m.contract.UUID, ContractUuid: m.contract.UUID,
}) })
if err != nil { if err != nil {
...@@ -139,7 +139,7 @@ func (m *SignatureManager) SendReadySign() (signatureUUID string, err error) { ...@@ -139,7 +139,7 @@ func (m *SignatureManager) SendReadySign() (signatureUUID string, err error) {
} }
errorCode := launch.GetErrorCode() errorCode := launch.GetErrorCode()
if errorCode.Code != api.ErrorCode_SUCCESS { if errorCode.Code != pAPI.ErrorCode_SUCCESS {
err = errors.New(errorCode.Code.String() + " " + errorCode.Message) err = errors.New(errorCode.Code.String() + " " + errorCode.Message)
return return
} }
......
...@@ -41,7 +41,7 @@ func TestNewContract(t *testing.T) { ...@@ -41,7 +41,7 @@ func TestNewContract(t *testing.T) {
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
// Register client1 // Register client1
client1, err := createClient(workingDir, ca) client1, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client1, "client1@example.com", "password", "", true, true) err = registerAndAuth(client1, "client1@example.com", "password", "", true, true)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
...@@ -72,7 +72,7 @@ func TestNewContract(t *testing.T) { ...@@ -72,7 +72,7 @@ func TestNewContract(t *testing.T) {
assert.T(t, len(contract.Signers[1].Hash) == 0) assert.T(t, len(contract.Signers[1].Hash) == 0)
// Register second signer // Register second signer
client2, err := createClient(workingDir, ca) client2, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client2, "client2@example.com", "password2", "", true, true) err = registerAndAuth(client2, "client2@example.com", "password2", "", true, true)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
...@@ -119,7 +119,7 @@ func TestNewContract(t *testing.T) { ...@@ -119,7 +119,7 @@ func TestNewContract(t *testing.T) {
assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, err)
// Bad case: no authentication // Bad case: no authentication
client3, err := createClient(workingDir, ca) client3, err := createClient(workingDir, ca, 0)
setLastArg(client3, "new", false) setLastArg(client3, "new", false)
client3.Stdin = strings.NewReader( client3.Stdin = strings.NewReader(
"\n" + "\n" +
......
...@@ -43,43 +43,43 @@ func TestRegisterAuth(t *testing.T) { ...@@ -43,43 +43,43 @@ func TestRegisterAuth(t *testing.T) {
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
// Register client1 // Register client1
client1, err := createClient(workingDir, ca) client1, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client1, "test@example.com", "password", "", true, true) err = registerAndAuth(client1, "test@example.com", "password", "", true, true)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
// Register client2 // Register client2
client2, err := createClient(workingDir, ca) client2, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client2, "test2@example.com", "", "2048", true, true) err = registerAndAuth(client2, "test2@example.com", "", "2048", true, true)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
// Register client3 // Register client3
client3, err := createClient(workingDir, ca) client3, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client3, "test@example.com", "", "", true, true) err = registerAndAuth(client3, "test@example.com", "", "", true, true)
assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, err)
// Register client4 // Register client4
client4, err := createClient(workingDir, ca) client4, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client4, "test wrong mail", "", "", true, true) err = registerAndAuth(client4, "test wrong mail", "", "", true, true)
assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, err)
// Register client5 // Register client5
client5, err := createClient(workingDir, ca) client5, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client5, "wrong@key.fr", "", "1024", true, true) err = registerAndAuth(client5, "wrong@key.fr", "", "1024", true, true)
assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, err)
// Register client6 // Register client6
client6, err := createClient(workingDir, ca) client6, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client6, "bad@auth.com", "", "", false, true) err = registerAndAuth(client6, "bad@auth.com", "", "", false, true)
assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, err)
// Register client7 // Register client7
client7, err := createClient(workingDir, ca) client7, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client7, "bad@auth2.com", "", "", true, false) err = registerAndAuth(client7, "bad@auth2.com", "", "", true, false)
assert.NotEqual(t, nil, err) assert.NotEqual(t, nil, err)
......
...@@ -32,15 +32,15 @@ func TestSignContract(t *testing.T) { ...@@ -32,15 +32,15 @@ func TestSignContract(t *testing.T) {
// Register clients // Register clients
clients := make([]*exec.Cmd, 3) clients := make([]*exec.Cmd, 3)
client1, err := createClient(workingDir, ca) client1, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client1, "client1@example.com", "password", "", true, true) err = registerAndAuth(client1, "client1@example.com", "password", "", true, true)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
client2, err := createClient(workingDir, ca) client2, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client2, "client2@example.com", "password", "", true, true) err = registerAndAuth(client2, "client2@example.com", "password", "", true, true)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
client3, err := createClient(workingDir, ca) client3, err := createClient(workingDir, ca, 0)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
err = registerAndAuth(client3, "client3@example.com", "password", "", true, true) err = registerAndAuth(client3, "client3@example.com", "password", "", true, true)
assert.Equal(t, nil, err) assert.Equal(t, nil, err)
......
...@@ -50,7 +50,7 @@ func startPlatform(tmpDir string) (*exec.Cmd, []byte, error) { ...@@ -50,7 +50,7 @@ func startPlatform(tmpDir string) (*exec.Cmd, []byte, error) {
// createClient creates a new working directory for a client, creating ca.pem. // createClient creates a new working directory for a client, creating ca.pem.
// It returns a ready-to-run command, but you probably want to set the last argument of the command. // It returns a ready-to-run command, but you probably want to set the last argument of the command.
func createClient(tmpDir string, ca []byte) (*exec.Cmd, error) { func createClient(tmpDir string, ca []byte, port int) (*exec.Cmd, error) {
path := filepath.Join(os.Getenv("GOPATH"), "bin", "dfssc") path := filepath.Join(os.Getenv("GOPATH"), "bin", "dfssc")
// Create temporary directory for client // Create temporary directory for client
...@@ -73,7 +73,7 @@ func createClient(tmpDir string, ca []byte) (*exec.Cmd, error) { ...@@ -73,7 +73,7 @@ func createClient(tmpDir string, ca []byte) (*exec.Cmd, error) {
// Prepare the client command. // Prepare the client command.
// The last argument is up to you! // The last argument is up to you!
cmd := exec.Command(path, "-ca", caPath, "-cert", certPath, "-host", "localhost:"+testPort, "-key", keyPath, "-v") cmd := exec.Command(path, "-ca", caPath, "-cert", certPath, "-host", "127.0.0.1:"+testPort, "-key", keyPath, "-port", strconv.Itoa(port), "-v")
return cmd, nil return cmd, nil
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment