Skip to content

Commit

Permalink
Allow users to change the client's username and password (#13)
Browse files Browse the repository at this point in the history
* Allow users to change the client's username and password

Signed-off-by: Lucas Caparelli <[email protected]>

* Add way to set username and password in one go

Signed-off-by: Lucas Caparelli <[email protected]>

* Add missing unit test

Signed-off-by: Lucas Caparelli <[email protected]>
  • Loading branch information
LCaparelli authored Jul 14, 2020
1 parent 622adfa commit 2668b02
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions nexus/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ func NewDefaultClient(baseURL string) *Client {
return NewClient(baseURL).Build()
}

// SetCredentials sets the client username and password
func (c *Client) SetCredentials(username, password string) {
c.username = username
c.password = password
}

// SetUsername sets the client username
func (c *Client) SetUsername(username string) {
c.username = username
}

// SetPassword sets the client password
func (c *Client) SetPassword(password string) {
c.password = password
}

// ScriptsRequired checks if the target Nexus server has APIs capabilities without relying on Groovy scripts.
// This should be used if the caller is not sure if the server accepts the capabilities offered by this library, since for
// security reasons and to comply with Nexus Server default policy, it does not support Groovy scripts execution.
Expand Down
23 changes: 23 additions & 0 deletions nexus/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,26 @@ func TestClient_IsNonScriptOperationsEnabled_NewServers(t *testing.T) {
assert.NoError(t, err)
assert.False(t, enabled)
}

func TestClient_SetCredentials(t *testing.T) {
c := &Client{}
username := "test-username"
password := "test-password"
c.SetCredentials(username, password)
assert.Equal(t, username, c.username)
assert.Equal(t, password, c.password)
}

func TestClient_SetUsername(t *testing.T) {
c := &Client{}
username := "test-username"
c.SetUsername(username)
assert.Equal(t, username, c.username)
}

func TestClient_SetPassword(t *testing.T) {
c := &Client{}
password := "test-password"
c.SetPassword(password)
assert.Equal(t, password, c.password)
}

0 comments on commit 2668b02

Please sign in to comment.