<commit_before>package authenticators_test

import (
	"encoding/json"

	"github.com/cloudfoundry-incubator/diego-ssh/authenticators"
	"github.com/cloudfoundry-incubator/diego-ssh/routes"
	"github.com/cloudfoundry-incubator/diego-ssh/test_helpers/fake_ssh"
	"github.com/cloudfoundry-incubator/receptor"
	"github.com/cloudfoundry-incubator/receptor/fake_receptor"
	"github.com/cloudfoundry-incubator/route-emitter/cfroutes"
	"github.com/pivotal-golang/lager/lagertest"
	"golang.org/x/crypto/ssh"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("DiegoProxyAuthenticator", func() {
	var (
		receptorClient     *fake_receptor.FakeClient
		expectedRoute      routes.SSHRoute
		desiredLRPResponse receptor.DesiredLRPResponse
		actualLrpResponse  receptor.ActualLRPResponse
	)

	BeforeEach(func() {
		receptorClient = new(fake_receptor.FakeClient)

		cfRoutes, err := json.Marshal(cfroutes.CFRoutes{
			cfroutes.CFRoute{
				Hostnames: []string{"host1.example.com", "host2.example.com"},
				Port:      8080,
			},
		})
		Ω(err).ShouldNot(HaveOccurred())

		expectedRoute = routes.SSHRoute{
			ContainerPort:   1111,
			PrivateKey:      "pem-encoded-key",
			HostFingerprint: "host-fingerprint",
			User:            "user",
			Password:        "password",
		}

		diegoSSHRoutePayload, err := json.Marshal(expectedRoute)
		Ω(err).ShouldNot(HaveOccurred())

		cfRoutesMessage := json.RawMessage(cfRoutes)
		diegoSSHRouteMessage := json.RawMessage(diegoSSHRoutePayload)

		desiredLRPResponse = receptor.DesiredLRPResponse{
			ProcessGuid: "some-guid",
			Instances:   2,
			Routes: receptor.RoutingInfo{
				cfroutes.CF_ROUTER: &cfRoutesMessage,
				routes.DIEGO_SSH:   &diegoSSHRouteMessage,
			},
		}

		actualLrpResponse = receptor.ActualLRPResponse{
			ProcessGuid:  "some-guid",
			Index:        0,
			InstanceGuid: "some-instance-guid",
			Address:      "1.2.3.4",
			Ports: []receptor.PortMapping{
				{ContainerPort: 1111, HostPort: 3333},
			},
		}

		receptorClient.ActualLRPByProcessGuidAndIndexReturns(actualLrpResponse, nil)
		receptorClient.GetDesiredLRPReturns(desiredLRPResponse, nil)
	})

	Describe("Authenticate", func() {
		var (
			authenticator *authenticators.DiegoProxyAuthenticator
			metadata      *fake_ssh.FakeConnMetadata<commit_msg>Remove unnecessary CF routes from ssh test<commit_after>package authenticators_test

import (
	"encoding/json"

	"github.com/cloudfoundry-incubator/diego-ssh/authenticators"
	"github.com/cloudfoundry-incubator/diego-ssh/routes"
	"github.com/cloudfoundry-incubator/diego-ssh/test_helpers/fake_ssh"
	"github.com/cloudfoundry-incubator/receptor"
	"github.com/cloudfoundry-incubator/receptor/fake_receptor"
	"github.com/pivotal-golang/lager/lagertest"
	"golang.org/x/crypto/ssh"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("DiegoProxyAuthenticator", func() {
	var (
		receptorClient     *fake_receptor.FakeClient
		expectedRoute      routes.SSHRoute
		desiredLRPResponse receptor.DesiredLRPResponse
		actualLrpResponse  receptor.ActualLRPResponse
	)

	BeforeEach(func() {
		receptorClient = new(fake_receptor.FakeClient)

		expectedRoute = routes.SSHRoute{
			ContainerPort:   1111,
			PrivateKey:      "pem-encoded-key",
			HostFingerprint: "host-fingerprint",
			User:            "user",
			Password:        "password",
		}

		diegoSSHRoutePayload, err := json.Marshal(expectedRoute)
		Ω(err).ShouldNot(HaveOccurred())

		diegoSSHRouteMessage := json.RawMessage(diegoSSHRoutePayload)

		desiredLRPResponse = receptor.DesiredLRPResponse{
			ProcessGuid: "some-guid",
			Instances:   2,
			Routes: receptor.RoutingInfo{
				routes.DIEGO_SSH: &diegoSSHRouteMessage,
			},
		}

		actualLrpResponse = receptor.ActualLRPResponse{
			ProcessGuid:  "some-guid",
			Index:        0,
			InstanceGuid: "some-instance-guid",
			Address:      "1.2.3.4",
			Ports: []receptor.PortMapping{
				{ContainerPort: 1111, HostPort: 3333},
			},
		}

		receptorClient.ActualLRPByProcessGuidAndIndexReturns(actualLrpResponse, nil)
		receptorClient.GetDesiredLRPReturns(desiredLRPResponse, nil)
	})

	Describe("Authenticate", func() {
		var (
			authenticator *authenticators.DiegoProxyAuthenticator
			metadata      *fake_ssh.FakeConnMetadata
{'fraction_non_alphanumeric': 0.11492078505556869, 'fraction_numerical': 0.009931425868999763, 'mean_word_length': 4.374841168996188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5928970', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1485, 'n_words': 186}