github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/go/apps/roughtime/server_test.go (about)

     1  // Copyright (c) 2016, Google Inc. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // This file contains tests for the adapted roughtime server and client
    16  // Significant portion of this code is modified version of what is in
    17  // the original roughtime repository
    18  package roughtime
    19  
    20  import (
    21  	"crypto/x509/pkix"
    22  	"fmt"
    23  	"io/ioutil"
    24  	"log"
    25  	"path"
    26  	"testing"
    27  	"time"
    28  
    29  	"github.com/golang/protobuf/proto"
    30  	"github.com/jlmucb/cloudproxy/go/apps/roughtime/agl_roughtime/config"
    31  	"github.com/jlmucb/cloudproxy/go/tao"
    32  )
    33  
    34  var (
    35  	domainPath             = "roughttime_test_domain"
    36  	x509Identity pkix.Name = pkix.Name{
    37  		Organization:       []string{"Google Inc."},
    38  		OrganizationalUnit: []string{"Cloud Security"},
    39  	}
    40  )
    41  
    42  func makeTrivialDomain() (*tao.Domain, error) {
    43  	var policyDomainConfig tao.DomainConfig
    44  	policyDomainConfig.SetDefaults()
    45  	policyDomainConfig.DomainInfo.GuardType = proto.String("AllowAll")
    46  	configPath := path.Join(domainPath, "tao.config")
    47  	return tao.CreateDomain(policyDomainConfig, configPath, []byte("xxx"))
    48  }
    49  
    50  func TestCreateChain(t *testing.T) {
    51  	domain, err := makeTrivialDomain()
    52  	if err != nil {
    53  		log.Fatal(err)
    54  	}
    55  
    56  	tmpDir, err := ioutil.TempDir("", domainPath)
    57  	if err != nil {
    58  		log.Fatal(err)
    59  	}
    60  	st, err := tao.NewSoftTao(tmpDir, []byte("xxx"))
    61  	if err != nil {
    62  		t.Fatal(err)
    63  	}
    64  
    65  	numServers := 2
    66  	servers := make([]config.Server, numServers)
    67  	for i := 0; i < numServers; i++ {
    68  		server, err := NewServer(domain.ConfigPath, network, 8000+i, &x509Identity, st)
    69  		if err != nil {
    70  			log.Fatal(err)
    71  		}
    72  		go server.ServeForever()
    73  		serverCfg := config.Server{
    74  			Name:          fmt.Sprintf("Test%d", i),
    75  			PublicKeyType: "ed25519",
    76  			PublicKey:     server.publicKey,
    77  			Addresses:     []config.ServerAddress{config.ServerAddress{network, fmt.Sprintf("localhost:%d", 8000+i)}},
    78  		}
    79  		servers[i] = serverCfg
    80  	}
    81  	time.Sleep(time.Second)
    82  
    83  	quorum := numServers
    84  	client, err := NewClient(domain.ConfigPath, network, quorum, servers)
    85  	if err != nil {
    86  		t.Fatal(err)
    87  	}
    88  
    89  	chain := &config.Chain{}
    90  	chain, err = client.Do(chain)
    91  	if err != nil {
    92  		t.Fatal(err)
    93  	}
    94  }