github.com/avenga/couper@v1.12.2/eval/lib/saml_internal_test.go (about)

     1  package lib
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/russellhaering/gosaml2/types"
     7  )
     8  
     9  func Test_getNameIDFormat(t *testing.T) {
    10  	tests := []struct {
    11  		name             string
    12  		supportedFormats []types.NameIDFormat
    13  		wantFormat       string
    14  	}{
    15  		{
    16  			"only unspecified",
    17  			[]types.NameIDFormat{
    18  				{Value: "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"},
    19  			},
    20  			"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
    21  		},
    22  		{
    23  			"unspecified 1st",
    24  			[]types.NameIDFormat{
    25  				{Value: "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"},
    26  				{Value: "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"},
    27  				{Value: "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"},
    28  			},
    29  			"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
    30  		},
    31  		{
    32  			"unspecified 2nd",
    33  			[]types.NameIDFormat{
    34  				{Value: "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"},
    35  				{Value: "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"},
    36  				{Value: "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"},
    37  			},
    38  			"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified",
    39  		},
    40  		{
    41  			"no unspecified",
    42  			[]types.NameIDFormat{
    43  				{Value: "urn:oasis:names:tc:SAML:2.0:nameid-format:transient"},
    44  				{Value: "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"},
    45  				{Value: "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"},
    46  			},
    47  			"urn:oasis:names:tc:SAML:2.0:nameid-format:transient",
    48  		},
    49  	}
    50  	for _, tt := range tests {
    51  		t.Run(tt.name, func(subT *testing.T) {
    52  			format := getNameIDFormat(tt.supportedFormats)
    53  			if format != tt.wantFormat {
    54  				subT.Errorf("Expected format %q, got: %#v", tt.wantFormat, format)
    55  			}
    56  		})
    57  	}
    58  }