@ -9,7 +9,6 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net"
"net/http"
@ -2328,7 +2327,7 @@ func testAgent_PersistService(t *testing.T, extraHCL string) {
if err != nil {
t . Fatalf ( "err: %s" , err )
}
content , err := ioutil . ReadFile ( file )
content , err := os . ReadFile ( file )
if err != nil {
t . Fatalf ( "err: %s" , err )
}
@ -2349,7 +2348,7 @@ func testAgent_PersistService(t *testing.T, extraHCL string) {
if err != nil {
t . Fatalf ( "err: %s" , err )
}
content , err = ioutil . ReadFile ( file )
content , err = os . ReadFile ( file )
if err != nil {
t . Fatalf ( "err: %s" , err )
}
@ -2418,7 +2417,7 @@ func testAgent_persistedService_compat(t *testing.T, extraHCL string) {
if err := os . MkdirAll ( filepath . Dir ( file ) , 0700 ) ; err != nil {
t . Fatalf ( "err: %s" , err )
}
if err := ioutil . WriteFile ( file , encoded , 0600 ) ; err != nil {
if err := os . WriteFile ( file , encoded , 0600 ) ; err != nil {
t . Fatalf ( "err: %s" , err )
}
@ -2473,7 +2472,7 @@ func testAgent_persistedService_compat_hash(t *testing.T, extraHCL string) {
if err := os . MkdirAll ( filepath . Dir ( file ) , 0700 ) ; err != nil {
t . Fatalf ( "err: %s" , err )
}
if err := ioutil . WriteFile ( file , encoded , 0600 ) ; err != nil {
if err := os . WriteFile ( file , encoded , 0600 ) ; err != nil {
t . Fatalf ( "err: %s" , err )
}
@ -2492,7 +2491,7 @@ func testAgent_persistedService_compat_hash(t *testing.T, extraHCL string) {
if err := os . MkdirAll ( filepath . Dir ( configFile ) , 0700 ) ; err != nil {
t . Fatalf ( "err: %s" , err )
}
if err := ioutil . WriteFile ( configFile , encodedConfig , 0600 ) ; err != nil {
if err := os . WriteFile ( configFile , encodedConfig , 0600 ) ; err != nil {
t . Fatalf ( "err: %s" , err )
}
@ -2673,7 +2672,7 @@ func TestAgent_PersistCheck(t *testing.T) {
} )
require . NoError ( t , err )
content , err := ioutil . ReadFile ( file )
content , err := os . ReadFile ( file )
require . NoError ( t , err )
require . Equal ( t , expected , content )
@ -2688,7 +2687,7 @@ func TestAgent_PersistCheck(t *testing.T) {
Source : "local" ,
} )
require . NoError ( t , err )
content , err = ioutil . ReadFile ( file )
content , err = os . ReadFile ( file )
require . NoError ( t , err )
require . Equal ( t , expected , content )
a . Shutdown ( )
@ -3719,7 +3718,7 @@ func TestAgent_persistCheckState(t *testing.T) {
// Check the persisted file exists and has the content
file := filepath . Join ( a . Config . DataDir , checkStateDir , cid . StringHashSHA256 ( ) )
buf , err := ioutil . ReadFile ( file )
buf , err := os . ReadFile ( file )
if err != nil {
t . Fatalf ( "err: %s" , err )
}
@ -5138,9 +5137,9 @@ func TestAutoConfig_Integration(t *testing.T) {
caFile := filepath . Join ( cfgDir , "cacert.pem" )
keyFile := filepath . Join ( cfgDir , "key.pem" )
require . NoError ( t , ioutil . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( caFile , [ ] byte ( cacert ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( key ) , 0600 ) )
require . NoError ( t , os . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , os . WriteFile ( caFile , [ ] byte ( cacert ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( key ) , 0600 ) )
// generate a gossip key
gossipKey := make ( [ ] byte , 32 )
@ -5267,7 +5266,7 @@ func TestAutoConfig_Integration(t *testing.T) {
require . NotEqual ( r , cert1 , client . Agent . tlsConfigurator . Cert ( ) )
// check that the on disk certs match expectations
data , err := ioutil . ReadFile ( filepath . Join ( client . DataDir , "auto-config.json" ) )
data , err := os . ReadFile ( filepath . Join ( client . DataDir , "auto-config.json" ) )
require . NoError ( r , err )
rdr := strings . NewReader ( string ( data ) )
@ -5302,9 +5301,9 @@ func TestAgent_AutoEncrypt(t *testing.T) {
caFile := filepath . Join ( cfgDir , "cacert.pem" )
keyFile := filepath . Join ( cfgDir , "key.pem" )
require . NoError ( t , ioutil . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( caFile , [ ] byte ( cacert ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( key ) , 0600 ) )
require . NoError ( t , os . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , os . WriteFile ( caFile , [ ] byte ( cacert ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( key ) , 0600 ) )
hclConfig := TestACLConfigWithParams ( nil ) + `
verify_incoming = true
@ -5498,9 +5497,9 @@ func TestAgent_AutoReloadDoReload_WhenCertAndKeyUpdated(t *testing.T) {
caFile := filepath . Join ( certsDir , "cacert.pem" )
keyFile := filepath . Join ( certsDir , "key.pem" )
require . NoError ( t , ioutil . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( caFile , [ ] byte ( ca ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( privateKey ) , 0600 ) )
require . NoError ( t , os . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , os . WriteFile ( caFile , [ ] byte ( ca ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( privateKey ) , 0600 ) )
// generate a gossip key
gossipKey := make ( [ ] byte , 32 )
@ -5540,8 +5539,8 @@ func TestAgent_AutoReloadDoReload_WhenCertAndKeyUpdated(t *testing.T) {
ExtKeyUsage : [ ] x509 . ExtKeyUsage { x509 . ExtKeyUsageServerAuth , x509 . ExtKeyUsageClientAuth } ,
} )
require . NoError ( t , err )
require . NoError ( t , ioutil . WriteFile ( certFile , [ ] byte ( cert2 ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( privateKey2 ) , 0600 ) )
require . NoError ( t , os . WriteFile ( certFile , [ ] byte ( cert2 ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( privateKey2 ) , 0600 ) )
retry . Run ( t , func ( r * retry . R ) {
aeCert2 := srv . tlsConfigurator . Cert ( )
@ -5579,9 +5578,9 @@ func TestAgent_AutoReloadDoNotReload_WhenCaUpdated(t *testing.T) {
caFile := filepath . Join ( certsDir , "cacert.pem" )
keyFile := filepath . Join ( certsDir , "key.pem" )
require . NoError ( t , ioutil . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( caFile , [ ] byte ( ca ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( privateKey ) , 0600 ) )
require . NoError ( t , os . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , os . WriteFile ( caFile , [ ] byte ( ca ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( privateKey ) , 0600 ) )
// generate a gossip key
gossipKey := make ( [ ] byte , 32 )
@ -5614,7 +5613,7 @@ func TestAgent_AutoReloadDoNotReload_WhenCaUpdated(t *testing.T) {
ca2 , _ , err := tlsutil . GenerateCA ( tlsutil . CAOpts { Signer : signer } )
require . NoError ( t , err )
require . NoError ( t , ioutil . WriteFile ( caFile , [ ] byte ( ca2 ) , 0600 ) )
require . NoError ( t , os . WriteFile ( caFile , [ ] byte ( ca2 ) , 0600 ) )
// wait a bit to see if it get updated.
time . Sleep ( time . Second )
@ -5653,9 +5652,9 @@ func TestAgent_AutoReloadDoReload_WhenCertThenKeyUpdated(t *testing.T) {
caFile := filepath . Join ( certsDir , "cacert.pem" )
keyFile := filepath . Join ( certsDir , "key.pem" )
require . NoError ( t , ioutil . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( caFile , [ ] byte ( ca ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( privateKey ) , 0600 ) )
require . NoError ( t , os . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , os . WriteFile ( caFile , [ ] byte ( ca ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( privateKey ) , 0600 ) )
// generate a gossip key
gossipKey := make ( [ ] byte , 32 )
@ -5667,7 +5666,7 @@ func TestAgent_AutoReloadDoReload_WhenCertThenKeyUpdated(t *testing.T) {
hclConfig := TestACLConfigWithParams ( nil )
configFile := testutil . TempDir ( t , "config" ) + "/config.hcl"
require . NoError ( t , ioutil . WriteFile ( configFile , [ ] byte ( `
require . NoError ( t , os . WriteFile ( configFile , [ ] byte ( `
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5699,8 +5698,8 @@ func TestAgent_AutoReloadDoReload_WhenCertThenKeyUpdated(t *testing.T) {
} )
require . NoError ( t , err )
certFileNew := filepath . Join ( certsDir , "cert_new.pem" )
require . NoError ( t , ioutil . WriteFile ( certFileNew , [ ] byte ( certNew ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( configFile , [ ] byte ( `
require . NoError ( t , os . WriteFile ( certFileNew , [ ] byte ( certNew ) , 0600 ) )
require . NoError ( t , os . WriteFile ( configFile , [ ] byte ( `
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5723,7 +5722,7 @@ func TestAgent_AutoReloadDoReload_WhenCertThenKeyUpdated(t *testing.T) {
require . Equal ( r , cert1Key , cert . PrivateKey )
} )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( privateKeyNew ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( privateKeyNew ) , 0600 ) )
// cert should change as we did not update the associated key
time . Sleep ( 1 * time . Second )
@ -5762,9 +5761,9 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
caFile := filepath . Join ( certsDir , "cacert.pem" )
keyFile := filepath . Join ( certsDir , "key.pem" )
require . NoError ( t , ioutil . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( caFile , [ ] byte ( ca ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( privateKey ) , 0600 ) )
require . NoError ( t , os . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , os . WriteFile ( caFile , [ ] byte ( ca ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( privateKey ) , 0600 ) )
// generate a gossip key
gossipKey := make ( [ ] byte , 32 )
@ -5776,7 +5775,7 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
hclConfig := TestACLConfigWithParams ( nil )
configFile := testutil . TempDir ( t , "config" ) + "/config.hcl"
require . NoError ( t , ioutil . WriteFile ( configFile , [ ] byte ( `
require . NoError ( t , os . WriteFile ( configFile , [ ] byte ( `
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5809,7 +5808,7 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
} )
require . NoError ( t , err )
certFileNew := filepath . Join ( certsDir , "cert_new.pem" )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( privateKeyNew ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( privateKeyNew ) , 0600 ) )
// cert should not change as we did not update the associated key
time . Sleep ( 1 * time . Second )
retry . Run ( t , func ( r * retry . R ) {
@ -5819,8 +5818,8 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
require . Equal ( r , cert1Key , cert . PrivateKey )
} )
require . NoError ( t , ioutil . WriteFile ( certFileNew , [ ] byte ( certNew ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( configFile , [ ] byte ( `
require . NoError ( t , os . WriteFile ( certFileNew , [ ] byte ( certNew ) , 0600 ) )
require . NoError ( t , os . WriteFile ( configFile , [ ] byte ( `
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5854,7 +5853,7 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
ExtKeyUsage : [ ] x509 . ExtKeyUsage { x509 . ExtKeyUsageServerAuth , x509 . ExtKeyUsageClientAuth } ,
} )
require . NoError ( t , err )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( privateKeyNew2 ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( privateKeyNew2 ) , 0600 ) )
// cert should not change as we did not update the associated cert
time . Sleep ( 1 * time . Second )
retry . Run ( t , func ( r * retry . R ) {
@ -5864,7 +5863,7 @@ func TestAgent_AutoReloadDoReload_WhenKeyThenCertUpdated(t *testing.T) {
require . Equal ( r , cert2Key , cert . PrivateKey )
} )
require . NoError ( t , ioutil . WriteFile ( certFileNew , [ ] byte ( certNew2 ) , 0600 ) )
require . NoError ( t , os . WriteFile ( certFileNew , [ ] byte ( certNew2 ) , 0600 ) )
// cert should change as we did update the associated key
time . Sleep ( 1 * time . Second )
@ -5902,9 +5901,9 @@ func Test_coalesceTimerTwoPeriods(t *testing.T) {
caFile := filepath . Join ( certsDir , "cacert.pem" )
keyFile := filepath . Join ( certsDir , "key.pem" )
require . NoError ( t , ioutil . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( caFile , [ ] byte ( ca ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( privateKey ) , 0600 ) )
require . NoError ( t , os . WriteFile ( certFile , [ ] byte ( cert ) , 0600 ) )
require . NoError ( t , os . WriteFile ( caFile , [ ] byte ( ca ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( privateKey ) , 0600 ) )
// generate a gossip key
gossipKey := make ( [ ] byte , 32 )
@ -5916,7 +5915,7 @@ func Test_coalesceTimerTwoPeriods(t *testing.T) {
hclConfig := TestACLConfigWithParams ( nil )
configFile := testutil . TempDir ( t , "config" ) + "/config.hcl"
require . NoError ( t , ioutil . WriteFile ( configFile , [ ] byte ( `
require . NoError ( t , os . WriteFile ( configFile , [ ] byte ( `
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5952,8 +5951,8 @@ func Test_coalesceTimerTwoPeriods(t *testing.T) {
} )
require . NoError ( t , err )
certFileNew := filepath . Join ( certsDir , "cert_new.pem" )
require . NoError ( t , ioutil . WriteFile ( certFileNew , [ ] byte ( certNew ) , 0600 ) )
require . NoError ( t , ioutil . WriteFile ( configFile , [ ] byte ( `
require . NoError ( t , os . WriteFile ( certFileNew , [ ] byte ( certNew ) , 0600 ) )
require . NoError ( t , os . WriteFile ( configFile , [ ] byte ( `
encrypt = "`+gossipKeyEncoded+`"
encrypt_verify_incoming = true
encrypt_verify_outgoing = true
@ -5976,7 +5975,7 @@ func Test_coalesceTimerTwoPeriods(t *testing.T) {
require . Equal ( r , cert1Key , cert . PrivateKey )
} )
require . NoError ( t , ioutil . WriteFile ( keyFile , [ ] byte ( privateKeyNew ) , 0600 ) )
require . NoError ( t , os . WriteFile ( keyFile , [ ] byte ( privateKeyNew ) , 0600 ) )
// cert should change as we did not update the associated key
time . Sleep ( coalesceInterval * 2 )
@ -6181,7 +6180,7 @@ cloud {
func getExpectedCaPoolByFile ( t * testing . T ) * x509 . CertPool {
pool := x509 . NewCertPool ( )
data , err := ioutil . ReadFile ( "../test/ca/root.cer" )
data , err := os . ReadFile ( "../test/ca/root.cer" )
require . NoError ( t , err )
if ! pool . AppendCertsFromPEM ( data ) {
t . Fatal ( "could not add test ca ../test/ca/root.cer to pool" )
@ -6197,7 +6196,7 @@ func getExpectedCaPoolByDir(t *testing.T) *x509.CertPool {
for _ , entry := range entries {
filename := path . Join ( "../test/ca_path" , entry . Name ( ) )
data , err := ioutil . ReadFile ( filename )
data , err := os . ReadFile ( filename )
require . NoError ( t , err )
if ! pool . AppendCertsFromPEM ( data ) {