Skip to content

Commit

Permalink
Removing duplicate test code
Browse files Browse the repository at this point in the history
Changing endpoint to intercept address

Signed-off-by: gberl002 <[email protected]>
  • Loading branch information
gberl002 committed Feb 28, 2024
1 parent 01ede0a commit 2b94811
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 107 deletions.
94 changes: 0 additions & 94 deletions ziti/cmd/edge/quickstart_automated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,97 +51,3 @@ func TestEdgeQuickstartAutomated(t *testing.T) {
fmt.Println("Operation completed")
}
}

func TestMultipleZitiEdgeSecure(t *testing.T) {

ctx, cancel := context.WithCancel(context.Background())
_ = os.Setenv("ZITI_CTRL_EDGE_ADVERTISED_ADDRESS", "localhost") //force localhost
_ = os.Setenv("ZITI_ROUTER_NAME", "quickstart-router")
cmdComplete := make(chan bool)
qs := NewQuickStartCmd(os.Stdout, os.Stderr, ctx)
go func() {
err := qs.Execute()
if err != nil {
log.Fatal(err)
}
cmdComplete <- true
}()

ctrlAddy := helpers.GetCtrlEdgeAdvertisedAddress()
ctrlPort := helpers.GetCtrlEdgeAdvertisedPort()
ctrlUrl := fmt.Sprintf("https://%s:%s", ctrlAddy, ctrlPort)

service1Name := "service1"
service2Name := "service2"
dialAddress1 := "dialAddress1"
dialAddress2 := "dialAddress2"
params := fmt.Sprintf("tcp:%s:%s", ctrlAddy, ctrlPort)

c := make(chan struct{})
go waitForController(ctrlUrl, c)
timeout, _ := time.ParseDuration("60s")
select {
case <-c:
//completed normally
log.Info("controller online")
case <-time.After(timeout):
cancel()
panic("timed out waiting for controller")
}

// Wait for the controller to become available
zitiAdminUsername := os.Getenv("ZITI_USER")
if zitiAdminUsername == "" {
zitiAdminUsername = "admin"
}
zitiAdminPassword := os.Getenv("ZITI_PWD")
if zitiAdminPassword == "" {
zitiAdminPassword = "admin"
}

// Authenticate with the controller
zel := NewLoginCmd(os.Stdout, os.Stderr)
zel.SetArgs([]string{
"https://127.0.0.1:1280/edge/management/v1",
"--username=admin",
"--password=admin",
"-y",
})
err := zel.Execute()
if err != nil {
log.Fatal(err)
}

// Run ZES once
zes := newSecureCmd(os.Stdout, os.Stderr)
zes.SetArgs([]string{
service1Name,
params,
fmt.Sprintf("--endpoint=%s", dialAddress1),
})
err = zes.Execute()
if err != nil {
fmt.Printf("Error: %s", err)
}

// Run ZES twice
zes = newSecureCmd(os.Stdout, os.Stderr)
zes.SetArgs([]string{
service2Name,
params,
fmt.Sprintf("--endpoint=%s", dialAddress2),
})
err = zes.Execute()
if err != nil {
fmt.Printf("Error: %s", err)
}

// Check network components for validity

cancel() //terminate the running ctrl/router

select { //wait for quickstart to clean up
case <-cmdComplete:
fmt.Println("Operation completed")
}
}
12 changes: 6 additions & 6 deletions ziti/cmd/edge/quickstart_shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func performQuickstartTest(t *testing.T) {
testerIdent := getIdentityByName(client, testerUsername)
dialSP := createServicePolicy(client, "basic.web.smoke.test.service.dial", rest_model.DialBindDial, rest_model.Roles{"@" + *testerIdent.ID}, rest_model.Roles{"@" + *webTestService.ID})

testServiceEndpoint(t, client, hostingRouterName, serviceName, dialPort, testerUsername)
testInterceptAddress(t, client, hostingRouterName, serviceName, dialPort, testerUsername)

// Cleanup
deleteServiceConfigByID(client, dialSvcConfig.ID)
Expand Down Expand Up @@ -576,7 +576,7 @@ func performQuickstartTest(t *testing.T) {
zes.SetArgs([]string{
service1Name,
params,
fmt.Sprintf("--endpoint=%s", dialAddress1),
fmt.Sprintf("--interceptAddress=%s", dialAddress1),
})
err := zes.Execute()
if err != nil {
Expand All @@ -588,7 +588,7 @@ func performQuickstartTest(t *testing.T) {
zes.SetArgs([]string{
service2Name,
params,
fmt.Sprintf("--endpoint=%s", dialAddress2),
fmt.Sprintf("--interceptAddress=%s", dialAddress2),
})
err = zes.Execute()
if err != nil {
Expand Down Expand Up @@ -646,7 +646,7 @@ func createZESTestFunc(t *testing.T, params string, client *rest_management_api_
zes.SetArgs([]string{
serviceName,
params,
fmt.Sprintf("--endpoint=%s", dialAddress),
fmt.Sprintf("--interceptAddress=%s", dialAddress),
})
err := zes.Execute()
if err != nil {
Expand Down Expand Up @@ -674,7 +674,7 @@ func createZESTestFunc(t *testing.T, params string, client *rest_management_api_
fmt.Printf("Error: %s", err)
}

testServiceEndpoint(t, client, hostingRouterName, serviceName, dialPort, testerUsername)
testInterceptAddress(t, client, hostingRouterName, serviceName, dialPort, testerUsername)

// Cleanup
serviceBindConfName := serviceName + ".host.v1"
Expand All @@ -689,7 +689,7 @@ func createZESTestFunc(t *testing.T, params string, client *rest_management_api_
}
}

func testServiceEndpoint(t *testing.T, client *rest_management_api_client.ZitiEdgeManagement, hostingRouterName string, serviceName string, dialPort int, testerUsername string) {
func testInterceptAddress(t *testing.T, client *rest_management_api_client.ZitiEdgeManagement, hostingRouterName string, serviceName string, dialPort int, testerUsername string) {
// Test connectivity with private edge router, wait some time for the terminator to be created
currentCount := getTerminatorCountByRouterName(client, hostingRouterName)
termCntReached := waitForTerminatorCountByRouterName(client, hostingRouterName, currentCount+1, 30*time.Second)
Expand Down
14 changes: 7 additions & 7 deletions ziti/cmd/edge/secure.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ import (
)

const (
optionEndpoint = "endpoint"
optionInterceptAddress = "interceptAddress"
)

// SecureOptions the options for the secure command
type SecureOptions struct {
common.CommonOptions
api.EntityOptions

Endpoint string
InterceptAddress string
}

// newSecureCmd consolidates network configuration steps for securing a service.
Expand All @@ -66,7 +66,7 @@ func newSecureCmd(out io.Writer, errOut io.Writer) *cobra.Command {
},
}

cmd.Flags().StringVar(&options.Endpoint, optionEndpoint, "", "the custom endpoint name for your service")
cmd.Flags().StringVar(&options.InterceptAddress, optionInterceptAddress, "", "the custom intercept address for your service")
options.CommonOptions.AddCommonFlags(cmd)

return cmd
Expand Down Expand Up @@ -103,12 +103,12 @@ func runSecure(o *SecureOptions) (err error) {
}

// Create a dial config
endpoint := svcName + ".ziti"
if o.Endpoint != "" {
endpoint = o.Endpoint
interceptAddress := svcName + ".ziti"
if o.InterceptAddress != "" {
interceptAddress = o.InterceptAddress
}
dialCfgName := svcName + ".intercept.v1"
jsonStr = fmt.Sprintf(`{"protocols":["%s"], "addresses":["%s"], "portRanges":[{"low":%d, "high":%d}]}`, protocol, endpoint, port, port)
jsonStr = fmt.Sprintf(`{"protocols":["%s"], "addresses":["%s"], "portRanges":[{"low":%d, "high":%d}]}`, protocol, interceptAddress, port, port)

cmd = newCreateConfigCmd(os.Stdout, os.Stderr)
args = []string{dialCfgName, entities.InterceptV1, jsonStr}
Expand Down

0 comments on commit 2b94811

Please sign in to comment.