github.com/spreadshirt/mattermost-server@v5.3.2-0.20180927191755-a257d501df3d+incompatible/app/login_test.go (about)

     1  // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package app
     5  
     6  import (
     7  	"net/http"
     8  	"testing"
     9  )
    10  
    11  func TestCheckForClienSideCert(t *testing.T) {
    12  	th := Setup()
    13  	defer th.TearDown()
    14  
    15  	var tests = []struct {
    16  		pem           string
    17  		subject       string
    18  		expectedEmail string
    19  	}{
    20  		{"blah", "blah", ""},
    21  		{"blah", "C=US, ST=Maryland, L=Pasadena, O=Brent Baccala, OU=FreeSoft, CN=www.freesoft.org/emailAddress=test@test.com", "test@test.com"},
    22  		{"blah", "C=US, ST=Maryland, L=Pasadena, O=Brent Baccala, OU=FreeSoft, CN=www.freesoft.org/EmailAddress=test@test.com", ""},
    23  		{"blah", "CN=www.freesoft.org/EmailAddress=test@test.com, C=US, ST=Maryland, L=Pasadena, O=Brent Baccala, OU=FreeSoft", ""},
    24  	}
    25  
    26  	for _, tt := range tests {
    27  		r := &http.Request{Header: http.Header{}}
    28  		r.Header.Add("X-SSL-Client-Cert", tt.pem)
    29  		r.Header.Add("X-SSL-Client-Cert-Subject-DN", tt.subject)
    30  
    31  		_, _, actualEmail := th.App.CheckForClienSideCert(r)
    32  
    33  		if actualEmail != tt.expectedEmail {
    34  			t.Fatalf("CheckForClienSideCert(%v): expected %v, actual %v", tt.subject, tt.expectedEmail, actualEmail)
    35  		}
    36  	}
    37  }