Ejemplo n.º 1
0
func TestSSHTunnelInstance_with_Agent_and_InvalidUsername(t *testing.T) {
	_, err := sshtunnel.NewInstance(ai.SSHServer, ai.SSHUsername, ai.SSHPassword, ai.TargetHost, ai.ExposedBind, ai.ExposedPort)
	if err == nil {
		t.Error("Was able to connect with agent and invalid username :-/")
	}
}
Ejemplo n.º 2
0
func main() {
	if isHelpRequested() {
		fmt.Printf(helpMessage())
		os.Exit(1)
	}

	fmt.Printf(welcomeMessage())

	// Load defaults: built-in or from file (only if it exists)
	d, err := loadDefaults()
	if err != nil {
		log.Fatalf("Unable to load defaults: %s", err)
	}

	// Merge default config with params passed as command line arguments
	c, err := parseArguments(d)
	if err != nil {
		log.Fatalf("Error while parsing command line arguments: %s", err)
	}

	sshServer := c.SSHServer                                         // This variable may be mutated by failover API, if failover is enabled
	failoverServer := failoverSSHServer(c.SSHServer, c.FailoverPort) // If failover is enabled, go here on main server connection failure
	var failoverAPIError error                                       // A placeholder for the failover API error, if OMG we will spot one :/

	for {
		// Initialize instance of the SSH tunnel (at least try to!)
		tunnel, errT := sshtunnel.NewInstance(sshServer, c.SSHUsername, c.SSHPassword, c.TargetHost, c.ExposedBind, c.ExposedPort)
		if errT != nil {
			log.Printf("Error initializing SSH tunnel: %s (will retry)", errT)
			time.Sleep(retrySeconds * time.Second)

			if c.FailoverPort != 0 {
				if sshServer == c.SSHServer {
					failoverAPIError = failoverAPIRequest(sshServer, c.BuildID)
					if failoverAPIError != nil {
						log.Printf("Failover API request failed: %s", failoverAPIError)
					} else {
						sshServer = failoverServer
						log.Printf("* Will try failover server: %s", failoverServer)
					}
				} else {
					sshServer = c.SSHServer
				}
			}

			continue
		} else {
			log.Printf("[OK] SSH tunnel initialized!")
		}

		fmt.Printf(configInfo(*tunnel, c.BuildID)) // Inform about tunnel settings

		// Check, if listener really listens to specified bind address (GatewayPorts thing)
		b, errB := tunnel.ProbeExposedBind()
		if errB != nil {
			log.Printf("WARNING: %s", errB)
		}
		if tunnel.ExposedBind() != b && b != "0.0.0.0" {
			fmt.Printf(gatewayPortsNB())
		}

		// Vamos bandidos!!!
		errF := tunnel.Forward()
		if errF != nil {
			log.Printf("[OMG] Failure on forwarder: %s (will retry)", errF)
			time.Sleep(retrySeconds * time.Second)
		}

	}
}
Ejemplo n.º 3
0
// Try to bring up tunnel instances...
func TestSSHTunnelInstance_with_Agent_and_ValidCredentials(t *testing.T) {
	_, err := sshtunnel.NewInstance(av.SSHServer, av.SSHUsername, av.SSHPassword, av.TargetHost, av.ExposedBind, av.ExposedPort)
	if err != nil {
		t.Error("Unable to connect with agent and valid credentials")
	}
}