peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
package agent
import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/require"
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/api"
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
"github.com/hashicorp/consul/proto/pbpeering"
"github.com/hashicorp/consul/sdk/testutil/retry"
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
"github.com/hashicorp/consul/testrpc"
)
var validCA = `
-- -- - BEGIN CERTIFICATE -- -- -
MIICmDCCAj6gAwIBAgIBBzAKBggqhkjOPQQDAjAWMRQwEgYDVQQDEwtDb25zdWwg
Q0EgNzAeFw0xODA1MjExNjMzMjhaFw0yODA1MTgxNjMzMjhaMBYxFDASBgNVBAMT
C0NvbnN1bCBDQSA3MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAER0qlxjnRcMEr
iSGlH7G7dYU7lzBEmLUSMZkyBbClmyV8 + e8WANemjn + PLnCr40If9cmpr7RnC9Qk
GTaLnLiF16OCAXswggF3MA4GA1UdDwEB / wQEAwIBhjAPBgNVHRMBAf8EBTADAQH /
MGgGA1UdDgRhBF8xZjo5MTpjYTo0MTo4ZjphYzo2NzpiZjo1OTpjMjpmYTo0ZTo3
NTo1YzpkODpmMDo1NTpkZTpiZTo3NTpiODozMzozMTpkNToyNDpiMDowNDpiMzpl
ODo5Nzo1Yjo3ZTBqBgNVHSMEYzBhgF8xZjo5MTpjYTo0MTo4ZjphYzo2NzpiZjo1
OTpjMjpmYTo0ZTo3NTo1YzpkODpmMDo1NTpkZTpiZTo3NTpiODozMzozMTpkNToy
NDpiMDowNDpiMzplODo5Nzo1Yjo3ZTA / BgNVHREEODA2hjRzcGlmZmU6Ly8xMjRk
ZjVhMC05ODIwLTc2YzMtOWFhOS02ZjYyMTY0YmExYzIuY29uc3VsMD0GA1UdHgEB
/ wQzMDGgLzAtgisxMjRkZjVhMC05ODIwLTc2YzMtOWFhOS02ZjYyMTY0YmExYzIu
Y29uc3VsMAoGCCqGSM49BAMCA0gAMEUCIQDzkkI7R + 0 U12a + zq2EQhP / n2mHmta +
fs2hBxWIELGwTAIgLdO7RRw + z9nnxCIA6kNl //mIQb+PGItespiHZKAz74Q=
-- -- - END CERTIFICATE -- -- -
`
func TestHTTP_Peering_GenerateToken ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
a := NewTestAgent ( t , "" )
testrpc . WaitForTestAgent ( t , a . RPC , "dc1" )
t . Run ( "No Body" , func ( t * testing . T ) {
req , err := http . NewRequest ( "POST" , "/v1/peering/token" , nil )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusBadRequest , resp . Code )
body , _ := io . ReadAll ( resp . Body )
require . Contains ( t , string ( body ) , "The peering arguments must be provided in the body" )
} )
t . Run ( "Body Invalid" , func ( t * testing . T ) {
req , err := http . NewRequest ( "POST" , "/v1/peering/token" , bytes . NewReader ( [ ] byte ( "abc" ) ) )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusBadRequest , resp . Code )
body , _ := io . ReadAll ( resp . Body )
require . Contains ( t , string ( body ) , "Body decoding failed:" )
} )
t . Run ( "No Name" , func ( t * testing . T ) {
req , err := http . NewRequest ( "POST" , "/v1/peering/token" ,
bytes . NewReader ( [ ] byte ( ` { } ` ) ) )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusBadRequest , resp . Code )
body , _ := io . ReadAll ( resp . Body )
require . Contains ( t , string ( body ) , "PeerName is required" )
} )
// TODO(peering): add more failure cases
t . Run ( "Success" , func ( t * testing . T ) {
body := & pbpeering . GenerateTokenRequest {
PeerName : "peering-a" ,
}
bodyBytes , err := json . Marshal ( body )
require . NoError ( t , err )
req , err := http . NewRequest ( "POST" , "/v1/peering/token" , bytes . NewReader ( bodyBytes ) )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusOK , resp . Code , "expected 200, got %d: %v" , resp . Code , resp . Body . String ( ) )
var r pbpeering . GenerateTokenResponse
require . NoError ( t , json . NewDecoder ( resp . Body ) . Decode ( & r ) )
tokenJSON , err := base64 . StdEncoding . DecodeString ( r . PeeringToken )
require . NoError ( t , err )
var token structs . PeeringToken
require . NoError ( t , json . Unmarshal ( tokenJSON , & token ) )
require . Nil ( t , token . CA )
require . Equal ( t , [ ] string { fmt . Sprintf ( "127.0.0.1:%d" , a . config . ServerPort ) } , token . ServerAddresses )
require . Equal ( t , "server.dc1.consul" , token . ServerName )
// The PeerID in the token is randomly generated so we don't assert on its value.
require . NotEmpty ( t , token . PeerID )
} )
}
func TestHTTP_Peering_Establish ( t * testing . T ) {
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
a := NewTestAgent ( t , "" )
testrpc . WaitForTestAgent ( t , a . RPC , "dc1" )
t . Run ( "No Body" , func ( t * testing . T ) {
req , err := http . NewRequest ( "POST" , "/v1/peering/establish" , nil )
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusBadRequest , resp . Code )
body , _ := io . ReadAll ( resp . Body )
require . Contains ( t , string ( body ) , "The peering arguments must be provided in the body" )
} )
t . Run ( "Body Invalid" , func ( t * testing . T ) {
req , err := http . NewRequest ( "POST" , "/v1/peering/establish" , bytes . NewReader ( [ ] byte ( "abc" ) ) )
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusBadRequest , resp . Code )
body , _ := io . ReadAll ( resp . Body )
require . Contains ( t , string ( body ) , "Body decoding failed:" )
} )
t . Run ( "No Name" , func ( t * testing . T ) {
req , err := http . NewRequest ( "POST" , "/v1/peering/establish" ,
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
bytes . NewReader ( [ ] byte ( ` { } ` ) ) )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusBadRequest , resp . Code )
body , _ := io . ReadAll ( resp . Body )
require . Contains ( t , string ( body ) , "PeerName is required" )
} )
t . Run ( "No Token" , func ( t * testing . T ) {
req , err := http . NewRequest ( "POST" , "/v1/peering/establish" ,
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
bytes . NewReader ( [ ] byte ( ` { "PeerName": "peer1-usw1"} ` ) ) )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusBadRequest , resp . Code )
body , _ := io . ReadAll ( resp . Body )
require . Contains ( t , string ( body ) , "PeeringToken is required" )
} )
// TODO(peering): add more failure cases
t . Run ( "Success" , func ( t * testing . T ) {
token := structs . PeeringToken {
CA : [ ] string { validCA } ,
ServerName : "server.dc1.consul" ,
ServerAddresses : [ ] string { fmt . Sprintf ( "1.2.3.4:%d" , 443 ) } ,
PeerID : "a0affd3e-f1c8-4bb9-9168-90fd902c441d" ,
}
tokenJSON , _ := json . Marshal ( & token )
tokenB64 := base64 . StdEncoding . EncodeToString ( tokenJSON )
body := & pbpeering . EstablishRequest {
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
PeerName : "peering-a" ,
PeeringToken : tokenB64 ,
Meta : map [ string ] string { "foo" : "bar" } ,
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
}
bodyBytes , err := json . Marshal ( body )
require . NoError ( t , err )
req , err := http . NewRequest ( "POST" , "/v1/peering/establish" , bytes . NewReader ( bodyBytes ) )
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusOK , resp . Code , "expected 200, got %d: %v" , resp . Code , resp . Body . String ( ) )
// success response does not currently return a value so {} is correct
require . Equal ( t , "{}" , resp . Body . String ( ) )
} )
}
func TestHTTP_Peering_MethodNotAllowed ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
a := NewTestAgent ( t , "" )
testrpc . WaitForTestAgent ( t , a . RPC , "dc1" )
ctx , cancel := context . WithTimeout ( context . Background ( ) , 5 * time . Second )
defer cancel ( )
// Insert peerings directly to state store.
// Note that the state store holds reference to the underlying
// variables; do not modify them after writing.
foo := & pbpeering . PeeringWriteRequest {
Peering : & pbpeering . Peering {
Name : "foo" ,
State : pbpeering . PeeringState_INITIAL ,
PeerCAPems : nil ,
PeerServerName : "fooservername" ,
PeerServerAddresses : [ ] string { "addr1" } ,
} ,
}
_ , err := a . rpcClientPeering . PeeringWrite ( ctx , foo )
require . NoError ( t , err )
req , err := http . NewRequest ( "PUT" , "/v1/peering/foo" , nil )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusMethodNotAllowed , resp . Code )
}
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
func TestHTTP_Peering_Read ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
a := NewTestAgent ( t , "" )
testrpc . WaitForTestAgent ( t , a . RPC , "dc1" )
ctx , cancel := context . WithTimeout ( context . Background ( ) , 5 * time . Second )
defer cancel ( )
// Insert peerings directly to state store.
// Note that the state store holds reference to the underlying
// variables; do not modify them after writing.
foo := & pbpeering . PeeringWriteRequest {
Peering : & pbpeering . Peering {
Name : "foo" ,
State : pbpeering . PeeringState_INITIAL ,
PeerCAPems : nil ,
PeerServerName : "fooservername" ,
PeerServerAddresses : [ ] string { "addr1" } ,
Meta : map [ string ] string { "foo" : "bar" } ,
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
} ,
}
_ , err := a . rpcClientPeering . PeeringWrite ( ctx , foo )
require . NoError ( t , err )
bar := & pbpeering . PeeringWriteRequest {
Peering : & pbpeering . Peering {
Name : "bar" ,
State : pbpeering . PeeringState_ACTIVE ,
PeerCAPems : nil ,
PeerServerName : "barservername" ,
PeerServerAddresses : [ ] string { "addr1" } ,
} ,
}
_ , err = a . rpcClientPeering . PeeringWrite ( ctx , bar )
require . NoError ( t , err )
t . Run ( "return foo" , func ( t * testing . T ) {
req , err := http . NewRequest ( "GET" , "/v1/peering/foo" , nil )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusOK , resp . Code )
var apiResp api . Peering
require . NoError ( t , json . NewDecoder ( resp . Body ) . Decode ( & apiResp ) )
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
require . Equal ( t , foo . Peering . Name , apiResp . Name )
require . Equal ( t , foo . Peering . Meta , apiResp . Meta )
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
} )
t . Run ( "not found" , func ( t * testing . T ) {
req , err := http . NewRequest ( "GET" , "/v1/peering/baz" , nil )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusNotFound , resp . Code )
require . Equal ( t , "Peering not found for \"baz\"" , resp . Body . String ( ) )
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
} )
}
func TestHTTP_Peering_Delete ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
a := NewTestAgent ( t , "" )
testrpc . WaitForTestAgent ( t , a . RPC , "dc1" )
ctx , cancel := context . WithTimeout ( context . Background ( ) , 5 * time . Second )
defer cancel ( )
foo := & pbpeering . PeeringWriteRequest {
Peering : & pbpeering . Peering {
Name : "foo" ,
State : pbpeering . PeeringState_INITIAL ,
PeerCAPems : nil ,
PeerServerName : "fooservername" ,
PeerServerAddresses : [ ] string { "addr1" } ,
} ,
}
_ , err := a . rpcClientPeering . PeeringWrite ( ctx , foo )
require . NoError ( t , err )
t . Run ( "read existing token before attempting delete" , func ( t * testing . T ) {
req , err := http . NewRequest ( "GET" , "/v1/peering/foo" , nil )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusOK , resp . Code )
var apiResp api . Peering
require . NoError ( t , json . NewDecoder ( resp . Body ) . Decode ( & apiResp ) )
require . Equal ( t , foo . Peering . Name , apiResp . Name )
} )
t . Run ( "delete the existing token we just read" , func ( t * testing . T ) {
req , err := http . NewRequest ( "DELETE" , "/v1/peering/foo" , nil )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusOK , resp . Code )
require . Equal ( t , "" , resp . Body . String ( ) )
} )
t . Run ( "now the token is deleted and reads should yield a 404" , func ( t * testing . T ) {
retry . Run ( t , func ( r * retry . R ) {
req , err := http . NewRequest ( "GET" , "/v1/peering/foo" , nil )
require . NoError ( r , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( r , http . StatusNotFound , resp . Code )
} )
} )
t . Run ( "delete a token that does not exist" , func ( t * testing . T ) {
req , err := http . NewRequest ( "DELETE" , "/v1/peering/baz" , nil )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusOK , resp . Code )
} )
}
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
func TestHTTP_Peering_List ( t * testing . T ) {
if testing . Short ( ) {
t . Skip ( "too slow for testing.Short" )
}
t . Parallel ( )
a := NewTestAgent ( t , "" )
testrpc . WaitForTestAgent ( t , a . RPC , "dc1" )
ctx , cancel := context . WithTimeout ( context . Background ( ) , 5 * time . Second )
defer cancel ( )
// Insert peerings directly to state store.
// Note that the state store holds reference to the underlying
// variables; do not modify them after writing.
foo := & pbpeering . PeeringWriteRequest {
Peering : & pbpeering . Peering {
Name : "foo" ,
State : pbpeering . PeeringState_INITIAL ,
PeerCAPems : nil ,
PeerServerName : "fooservername" ,
PeerServerAddresses : [ ] string { "addr1" } ,
} ,
}
_ , err := a . rpcClientPeering . PeeringWrite ( ctx , foo )
require . NoError ( t , err )
bar := & pbpeering . PeeringWriteRequest {
Peering : & pbpeering . Peering {
Name : "bar" ,
State : pbpeering . PeeringState_ACTIVE ,
PeerCAPems : nil ,
PeerServerName : "barservername" ,
PeerServerAddresses : [ ] string { "addr1" } ,
} ,
}
_ , err = a . rpcClientPeering . PeeringWrite ( ctx , bar )
require . NoError ( t , err )
t . Run ( "return all" , func ( t * testing . T ) {
req , err := http . NewRequest ( "GET" , "/v1/peerings" , nil )
require . NoError ( t , err )
resp := httptest . NewRecorder ( )
a . srv . h . ServeHTTP ( resp , req )
require . Equal ( t , http . StatusOK , resp . Code )
var apiResp [ ] * api . Peering
require . NoError ( t , json . NewDecoder ( resp . Body ) . Decode ( & apiResp ) )
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
require . Len ( t , apiResp , 2 )
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
3 years ago
} )
}