Skip to content

Commit

Permalink
fix: issue #579 (space roles not exported) (#582)
Browse files Browse the repository at this point in the history
- The `addSpaceUsers` function needs the space GUID as a function param,
but instead the org GUID is supplied, resulting in no space users being
found as the supplied space GUID (which is actually an org GUI) does
not actually exist. This commit fixes this issue by correctly supplying
the space GUID.
  - this commit reverses [a past change](1483b66#diff-9982210b028e54f7afea530e407e1544509635e4dae9d236e2045280589b6b65L371)
  which lacks clear justification (so presumably it's an unintentional change).
- backfill an integration test that would have caught this regression.

[fixes #579]
[https://vmw-jira.broadcom.net/browse/TPCF-27431]
  • Loading branch information
peterhaochen47 authored Oct 19, 2024
1 parent 4083a63 commit 0fab7d1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion export/exportconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (im *Manager) processSpaces(globalConfig *config.GlobalConfig, orgConfig *c

spaceConfig := &config.SpaceConfig{Org: orgConfig.Org, Space: spaceName, EnableUnassignSecurityGroup: true}
//Add users
err = im.addSpaceUsers(spaceConfig, orgSpace.Relationships.Organization.Data.GUID)
err = im.addSpaceUsers(spaceConfig, orgSpace.GUID)
if err != nil {
return err
}
Expand Down
58 changes: 57 additions & 1 deletion integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package integration_test
import (
"bytes"
"fmt"
"github.com/vmwarepivotallabs/cf-mgmt/config"
"gopkg.in/yaml.v2"
"os"
"os/exec"
"strings"
Expand All @@ -14,7 +16,8 @@ import (
)

const (
configDir = "./fixture"
configDir = "./fixture"
exportedConfigDir = "./exported-config"
)

// cf runs the cf CLI with the specified args.
Expand Down Expand Up @@ -255,5 +258,58 @@ var _ = Describe("cf-mgmt cli", func() {
Expect(bytes.Contains(orgInfo, []byte("test2-iso-segment"))).Should(BeTrue())
})
})

Describe("export-config", func() {
BeforeEach(func() {
fmt.Println("******** Before called *********")

err := os.MkdirAll(exportedConfigDir, os.ModePerm)
Expect(err).ShouldNot(HaveOccurred())
// There seems to be an existing issue where if this ldap.yml does not exist, "cf-mgmt export-config" will fail with:
// "Unable to initialize cf-mgmt. Error : Error reading file exported-config/ldap.yml: open exported-config/ldap.yml: no such file or directory"
_, err = os.Create(exportedConfigDir + "/ldap.yml")
Expect(err).ShouldNot(HaveOccurred())

cf("create-org", "test-org")
cf("target", "-o", "test-org")
cf("create-space", "test-space")
cf("target", "-o", "test-org", "-s", "test-space")
})

AfterEach(func() {
fmt.Println("******** after called *********")

err := os.RemoveAll(exportedConfigDir)
Expect(err).ShouldNot(HaveOccurred())

cf("delete-space", "test-space", "-o", "test-org", "-f")
cf("delete-org", "-f", "test-org")
})

It("should complete successfully", func() {
orgs, err := cf("orgs")
Expect(err).ShouldNot(HaveOccurred())
Expect(string(orgs)).Should(ContainSubstring("test-org"))

By("exporting space roles")
exportConfigCommand := exec.Command(outPath, "export-config",
"--config-dir", exportedConfigDir,
"--system-domain", systemDomain,
"--user-id", userID,
"--password", password,
"--client-secret", clientSecret)
session, err := Start(exportConfigCommand, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
Eventually(session).Should(Exit(0))

spaceConfigFile, err := os.ReadFile(exportedConfigDir + "/test-org/test-space/spaceConfig.yml")
Expect(err).ShouldNot(HaveOccurred())
var spaceConfig config.SpaceConfig
yaml.Unmarshal(spaceConfigFile, &spaceConfig)

// the user that created the space is auto-assigned as a space developer; the exported config should reflect that
Expect(spaceConfig.Developer.Users).Should(ContainElement("admin"))
})
})
})
})

0 comments on commit 0fab7d1

Please # to comment.