Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type ClientParams struct {
// required: true
// example: My Client
Name string `form:"name" query:"name" json:"name" binding:"required"`
// The client source. Default api.
//
// example: api
Source string `form:"source" query:"source" json:"source"`
}

// UpdateClient updates a client by its id.
Expand Down Expand Up @@ -143,6 +147,11 @@ func (a *ClientAPI) CreateClient(ctx *gin.Context) {
Name: clientParams.Name,
Token: auth.GenerateNotExistingToken(generateClientToken, a.clientExists),
UserID: auth.GetUserID(ctx),
Source: model.ClientSourceApi,
}

if clientParams.Source != "" {
client.Source = clientParams.Source
}

if success := successOrAbort(ctx, 500, a.DB.CreateClient(&client)); !success {
Expand Down
15 changes: 8 additions & 7 deletions api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ func (s *ClientSuite) AfterTest(suiteName, testName string) {
}

func (s *ClientSuite) Test_ensureClientHasCorrectJsonRepresentation() {
actual := &model.Client{ID: 1, UserID: 2, Token: "Casdasfgeeg", Name: "myclient"}
test.JSONEquals(s.T(), actual, `{"id":1,"token":"Casdasfgeeg","name":"myclient","lastUsed":null}`)
actual := &model.Client{ID: 1, UserID: 2, Token: "Casdasfgeeg", Source: model.ClientSourceApi, Name: "myclient"}
test.JSONEquals(s.T(), actual, `{"id":1,"token":"Casdasfgeeg","name":"myclient","source":"api","lastUsed":null}`)
}

func (s *ClientSuite) Test_CreateClient_mapAllParameters() {
s.db.User(5)

test.WithUser(s.ctx, 5)
s.withFormData("name=custom_name&description=description_text")
s.withFormData("name=custom_name&description=description_text&source=custom")

s.a.CreateClient(s.ctx)

expected := &model.Client{ID: 1, Token: firstClientToken, UserID: 5, Name: "custom_name"}
expected := &model.Client{ID: 1, Token: firstClientToken, UserID: 5, Name: "custom_name", Source: "custom"}
assert.Equal(s.T(), 200, s.recorder.Code)
if clients, err := s.db.GetClientsByUser(5); assert.NoError(s.T(), err) {
assert.Contains(s.T(), clients, expected)
Expand All @@ -83,7 +83,7 @@ func (s *ClientSuite) Test_CreateClient_ignoresReadOnlyPropertiesInParams() {
s.withFormData("name=myclient&ID=45&Token=12341234&UserID=333")

s.a.CreateClient(s.ctx)
expected := &model.Client{ID: 1, UserID: 5, Token: firstClientToken, Name: "myclient"}
expected := &model.Client{ID: 1, UserID: 5, Token: firstClientToken, Name: "myclient", Source: model.ClientSourceApi}

assert.Equal(s.T(), 200, s.recorder.Code)
if clients, err := s.db.GetClientsByUser(5); assert.NoError(s.T(), err) {
Expand Down Expand Up @@ -127,7 +127,7 @@ func (s *ClientSuite) Test_CreateClient_returnsClientWithID() {

s.a.CreateClient(s.ctx)

expected := &model.Client{ID: 1, Token: firstClientToken, Name: "custom_name", UserID: 5}
expected := &model.Client{ID: 1, Token: firstClientToken, Name: "custom_name", UserID: 5, Source: model.ClientSourceApi}
assert.Equal(s.T(), 200, s.recorder.Code)
test.BodyEquals(s.T(), expected, s.recorder)
}
Expand All @@ -140,7 +140,7 @@ func (s *ClientSuite) Test_CreateClient_withExistingToken() {

s.a.CreateClient(s.ctx)

expected := &model.Client{ID: 2, Token: secondClientToken, Name: "custom_name", UserID: 5}
expected := &model.Client{ID: 2, Token: secondClientToken, Name: "custom_name", UserID: 5, Source: model.ClientSourceApi}
assert.Equal(s.T(), 200, s.recorder.Code)
test.BodyEquals(s.T(), expected, s.recorder)
}
Expand Down Expand Up @@ -200,6 +200,7 @@ func (s *ClientSuite) Test_UpdateClient_expectSuccess() {
Token: firstClientToken,
UserID: 5,
Name: "firefox",
Source: model.ClientSourceApi,
}

assert.Equal(s.T(), 200, s.recorder.Code)
Expand Down
2 changes: 1 addition & 1 deletion api/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type HealthAPI struct {
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eternal-flame-AD sorry this is kinda big, but would you mind having a look at this? Don't worry about declining if you don't want to review this, or don't have the time. I don't want to burden you with this :D.

Anyway, my plan is to create a snapshot docker build in the coming days and then let the people in #433 try out the functionality to improve the user-guide and find possible bugs with special IdP servers. So there is no rush reviewing this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can look at this tonight first to see if there are large architectural/security changes needed and we can do a final round for final check and nitpicks after the code settles. Probably won't review Android though because I'm not very familar with android dev.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks!


// Health returns health information.
// swagger:operation GET /health health getHealth
// swagger:operation GET /health info getHealth
//
// Get health information.
//
Expand Down
Loading
Loading