@@ -4,9 +4,11 @@ import (
44 "encoding/json"
55 "log/slog"
66 "os"
7+ "strings"
78 "testing"
89
910 "github.com/ghodss/yaml"
11+ "github.com/go-jose/go-jose/v4"
1012 "github.com/kylelemons/godebug/pretty"
1113
1214 "github.com/dexidp/dex/connector/mock"
@@ -481,10 +483,11 @@ logger:
481483
482484func TestSignerConfigUnmarshal (t * testing.T ) {
483485 tests := []struct {
484- name string
485- config string
486- wantErr bool
487- check func (* Config ) error
486+ name string
487+ config string
488+ wantErr bool
489+ errContains string
490+ check func (* Config ) error
488491 }{
489492 {
490493 name : "local signer with rotation period" ,
@@ -507,8 +510,84 @@ enablePasswordDB: true
507510 }
508511 if localConfig , ok := c .Signer .Config .(* signer.LocalConfig ); ! ok {
509512 t .Error ("expected LocalConfig" )
510- } else if localConfig .KeysRotationPeriod != "6h" {
511- t .Errorf ("expected keys rotation period '6h', got %q" , localConfig .KeysRotationPeriod )
513+ } else {
514+ if localConfig .KeysRotationPeriod != "6h" {
515+ t .Errorf ("expected keys rotation period '6h', got %q" , localConfig .KeysRotationPeriod )
516+ }
517+ if localConfig .Algorithm != jose .RS256 {
518+ t .Errorf ("expected default algorithm 'RS256', got %q" , localConfig .Algorithm )
519+ }
520+ }
521+ return nil
522+ },
523+ },
524+ {
525+ name : "local signer with ES256 algorithm" ,
526+ config : `
527+ issuer: http://127.0.0.1:5556/dex
528+ storage:
529+ type: memory
530+ web:
531+ http: 0.0.0.0:5556
532+ signer:
533+ type: local
534+ config:
535+ keysRotationPeriod: 6h
536+ algorithm: ES256
537+ enablePasswordDB: true
538+ ` ,
539+ wantErr : false ,
540+ check : func (c * Config ) error {
541+ localConfig , ok := c .Signer .Config .(* signer.LocalConfig )
542+ if ! ok {
543+ t .Error ("expected LocalConfig" )
544+ return nil
545+ }
546+ if localConfig .Algorithm != jose .ES256 {
547+ t .Errorf ("expected algorithm 'ES256', got %q" , localConfig .Algorithm )
548+ }
549+ return nil
550+ },
551+ },
552+ {
553+ name : "local signer with invalid algorithm" ,
554+ config : `
555+ issuer: http://127.0.0.1:5556/dex
556+ storage:
557+ type: memory
558+ web:
559+ http: 0.0.0.0:5556
560+ signer:
561+ type: local
562+ config:
563+ keysRotationPeriod: 6h
564+ algorithm: ES512
565+ enablePasswordDB: true
566+ ` ,
567+ wantErr : true ,
568+ errContains : `parse signer config: unsupported local signer algorithm "ES512"` ,
569+ },
570+ {
571+ name : "local signer without config" ,
572+ config : `
573+ issuer: http://127.0.0.1:5556/dex
574+ storage:
575+ type: memory
576+ web:
577+ http: 0.0.0.0:5556
578+ signer:
579+ type: local
580+ enablePasswordDB: true
581+ ` ,
582+ wantErr : false ,
583+ check : func (c * Config ) error {
584+ localConfig , ok := c .Signer .Config .(* signer.LocalConfig )
585+ if ! ok {
586+ t .Error ("expected LocalConfig" )
587+ return nil
588+ }
589+ if localConfig .Algorithm != jose .RS256 {
590+ t .Errorf ("expected default algorithm 'RS256', got %q" , localConfig .Algorithm )
512591 }
513592 return nil
514593 },
@@ -583,6 +662,10 @@ enablePasswordDB: true
583662 t .Errorf ("Unmarshal() error = %v, wantErr %v" , err , tt .wantErr )
584663 return
585664 }
665+ if tt .errContains != "" && (err == nil || ! strings .Contains (err .Error (), tt .errContains )) {
666+ t .Errorf ("Unmarshal() error = %v, want substring %q" , err , tt .errContains )
667+ return
668+ }
586669
587670 if err == nil && tt .check != nil {
588671 if err := tt .check (& c ); err != nil {
0 commit comments