@@ -444,6 +444,123 @@ func TestDoUpdate(t *testing.T) {
444444
445445}
446446
447+ func TestDoConfigUpdate (t * testing.T ) {
448+ t .Parallel ()
449+
450+ useragent := "testClient"
451+ ts := dnapitest .NewServer (useragent )
452+ t .Cleanup (func () { ts .Close () })
453+
454+ ca , caPrivkey := dnapitest .NebulaCACert ()
455+ caPEM , err := ca .MarshalPEM ()
456+ require .NoError (t , err )
457+
458+ c := NewClient (useragent , ts .URL )
459+
460+ code := "foobar"
461+ ts .ExpectEnrollment (code , message .NetworkCurve25519 , func (req message.EnrollRequest ) []byte {
462+ cfg , err := yaml .Marshal (m {
463+ "pki" : m {"ca" : string (caPEM )},
464+ })
465+ require .NoError (t , err )
466+
467+ return jsonMarshal (message.APIResponse [message.EnrollResponseData ]{
468+ Data : message.EnrollResponseData {
469+ HostID : "foobar" ,
470+ Counter : 1 ,
471+ Config : cfg ,
472+ TrustedKeys : ca .MarshalPublicKeyPEM (),
473+ Organization : message.HostOrgMetadata {
474+ ID : "foobaz" ,
475+ Name : "foobar's foo org" ,
476+ },
477+ Network : message.HostNetworkMetadata {
478+ ID : "qux" ,
479+ Name : "the best network" ,
480+ Curve : message .NetworkCurve25519 ,
481+ CIDR : "192.168.100.0/24" ,
482+ },
483+ Host : message.HostHostMetadata {
484+ ID : "quux" ,
485+ Name : "foo host" ,
486+ IPAddress : "192.168.100.2" ,
487+ },
488+ },
489+ })
490+ })
491+
492+ ctx , cancel := context .WithTimeout (context .Background (), 1 * time .Second )
493+ defer cancel ()
494+ _ , _ , creds , _ , err := c .Enroll (ctx , testutil .NewTestLogger (), code )
495+ require .NoError (t , err )
496+
497+ orgID := "foobaz"
498+ orgName := "foobar's foo org"
499+ netID := "qux"
500+ netName := "the best network"
501+ hostID := "foobar"
502+ hostName := "foo host"
503+ hostIP := "192.168.100.1"
504+ oidcEmail := "demo@defined.net"
505+ oidcExpiresAt := time .Now ().Add (24 * time .Hour ).UTC ().Truncate (time .Second )
506+
507+ ts .ExpectDNClientRequest (message .DoConfigUpdate , http .StatusOK , func (r message.RequestWrapper ) []byte {
508+ newConfigResponse := message.DoConfigUpdateResponse {
509+ Config : dnapitest .NebulaCfg (caPEM ),
510+ Counter : 2 ,
511+ Nonce : dnapitest .GetNonce (r ),
512+ TrustedKeys : ca .MarshalPublicKeyPEM (),
513+ Organization : message.HostOrgMetadata {
514+ ID : orgID ,
515+ Name : orgName ,
516+ },
517+ Network : message.HostNetworkMetadata {
518+ ID : netID ,
519+ Name : netName ,
520+ Curve : message .NetworkCurve25519 ,
521+ CIDR : "192.168.100.0/24" ,
522+ },
523+ Host : message.HostHostMetadata {
524+ ID : hostID ,
525+ Name : hostName ,
526+ IPAddress : hostIP ,
527+ },
528+ EndpointOIDCMeta : & message.HostEndpointOIDCMetadata {
529+ Email : oidcEmail ,
530+ ExpiresAt : & oidcExpiresAt ,
531+ },
532+ }
533+ rawRes := jsonMarshal (newConfigResponse )
534+
535+ return jsonMarshal (message.SignedResponseWrapper {
536+ Data : message.SignedResponse {
537+ Version : 1 ,
538+ Message : rawRes ,
539+ Signature : ed25519 .Sign (caPrivkey , rawRes ),
540+ },
541+ })
542+ })
543+
544+ ctx , cancel = context .WithTimeout (context .Background (), 1 * time .Second )
545+ defer cancel ()
546+ _ , _ , meta , err := c .DoConfigUpdate (ctx , * creds )
547+ require .NoError (t , err )
548+ assert .Empty (t , ts .Errors ())
549+ assert .Equal (t , 0 , ts .RequestsRemaining ())
550+
551+ assert .Equal (t , orgID , meta .Org .ID )
552+ assert .Equal (t , orgName , meta .Org .Name )
553+ assert .Equal (t , netID , meta .Network .ID )
554+ assert .Equal (t , netName , meta .Network .Name )
555+ assert .Equal (t , hostID , meta .Host .ID )
556+ assert .Equal (t , hostName , meta .Host .Name )
557+ assert .Equal (t , []string {hostIP }, meta .Host .IPAddresses )
558+ require .NotNil (t , meta .EndpointOIDC )
559+ assert .Equal (t , oidcEmail , meta .EndpointOIDC .Email )
560+ require .NotNil (t , meta .EndpointOIDC .ExpiresAt )
561+ assert .WithinDuration (t , oidcExpiresAt , * meta .EndpointOIDC .ExpiresAt , time .Second )
562+ }
563+
447564func TestDoUpdate_P256 (t * testing.T ) {
448565 t .Parallel ()
449566
0 commit comments