Skip to content

Commit

Permalink
add some additional checks to avoid false positives with existing VIN (
Browse files Browse the repository at this point in the history
…#432)

* add some additional checks to avoid false positives with existing VIN

* remove endpoints not being used. Add eth address to test helper

* fix auth test injector, fix tests

* update swag
  • Loading branch information
JamesReate authored Jan 23, 2025
1 parent aff9228 commit 22efd8d
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 382 deletions.
3 changes: 0 additions & 3 deletions cmd/devices-api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ func startWebAPI(logger zerolog.Logger, settings *config.Settings, pdb db.Store,
udOwner.Get("/commands/mint", userDeviceController.GetMintDevice)
udOwner.Post("/commands/mint", userDeviceController.PostMintDevice)

udOwner.Patch("/vin", userDeviceController.UpdateVIN)
udOwner.Patch("/country-code", userDeviceController.UpdateCountryCode)

udOwner.Post("/error-codes", userDeviceController.QueryDeviceErrorCodes)
udOwner.Get("/error-codes", userDeviceController.GetUserDeviceErrorCodeQueries)
udOwner.Post("/error-codes/clear", userDeviceController.ClearUserDeviceErrorCodeQuery)
Expand Down
85 changes: 0 additions & 85 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,41 +681,6 @@ const docTemplate = `{
}
}
},
"/user/devices/{userDeviceID}/country_code": {
"patch": {
"security": [
{
"BearerAuth": []
}
],
"description": "updates the CountryCode on the user device record",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"user-devices"
],
"parameters": [
{
"description": "Country code",
"name": "name",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_controllers.UpdateCountryCodeReq"
}
}
],
"responses": {
"204": {
"description": "No Content"
}
}
}
},
"/user/devices/{userDeviceID}/error-codes": {
"get": {
"security": [
Expand Down Expand Up @@ -1283,48 +1248,6 @@ const docTemplate = `{
}
}
},
"/user/devices/{userDeviceID}/vin": {
"patch": {
"security": [
{
"BearerAuth": []
}
],
"description": "Deprecated. updates the VIN on the user device record. Keeping this alive to not break mobile app. VIN's now come from attestations.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"user-devices"
],
"parameters": [
{
"description": "VIN",
"name": "vin",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_controllers.UpdateVINReq"
}
},
{
"type": "string",
"description": "user id",
"name": "userDeviceID",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "No Content"
}
}
}
},
"/user/devices/{userDeviceId}/commands/update-nft-image": {
"post": {
"security": [
Expand Down Expand Up @@ -2771,14 +2694,6 @@ const docTemplate = `{
}
}
},
"internal_controllers.UpdateCountryCodeReq": {
"type": "object",
"properties": {
"countryCode": {
"type": "string"
}
}
},
"internal_controllers.UpdateVINReq": {
"type": "object",
"required": [
Expand Down
85 changes: 0 additions & 85 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -673,41 +673,6 @@
}
}
},
"/user/devices/{userDeviceID}/country_code": {
"patch": {
"security": [
{
"BearerAuth": []
}
],
"description": "updates the CountryCode on the user device record",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"user-devices"
],
"parameters": [
{
"description": "Country code",
"name": "name",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_controllers.UpdateCountryCodeReq"
}
}
],
"responses": {
"204": {
"description": "No Content"
}
}
}
},
"/user/devices/{userDeviceID}/error-codes": {
"get": {
"security": [
Expand Down Expand Up @@ -1275,48 +1240,6 @@
}
}
},
"/user/devices/{userDeviceID}/vin": {
"patch": {
"security": [
{
"BearerAuth": []
}
],
"description": "Deprecated. updates the VIN on the user device record. Keeping this alive to not break mobile app. VIN's now come from attestations.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"user-devices"
],
"parameters": [
{
"description": "VIN",
"name": "vin",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_controllers.UpdateVINReq"
}
},
{
"type": "string",
"description": "user id",
"name": "userDeviceID",
"in": "path",
"required": true
}
],
"responses": {
"204": {
"description": "No Content"
}
}
}
},
"/user/devices/{userDeviceId}/commands/update-nft-image": {
"post": {
"security": [
Expand Down Expand Up @@ -2763,14 +2686,6 @@
}
}
},
"internal_controllers.UpdateCountryCodeReq": {
"type": "object",
"properties": {
"countryCode": {
"type": "string"
}
}
},
"internal_controllers.UpdateVINReq": {
"type": "object",
"required": [
Expand Down
53 changes: 0 additions & 53 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -719,11 +719,6 @@ definitions:
example: "2022-10-01T09:22:26.337Z"
type: string
type: object
internal_controllers.UpdateCountryCodeReq:
properties:
countryCode:
type: string
type: object
internal_controllers.UpdateVINReq:
properties:
canProtocol:
Expand Down Expand Up @@ -1183,27 +1178,6 @@ paths:
- BearerAuth: []
tags:
- user-devices
/user/devices/{userDeviceID}/country_code:
patch:
consumes:
- application/json
description: updates the CountryCode on the user device record
parameters:
- description: Country code
in: body
name: name
required: true
schema:
$ref: '#/definitions/internal_controllers.UpdateCountryCodeReq'
produces:
- application/json
responses:
"204":
description: No Content
security:
- BearerAuth: []
tags:
- user-devices
/user/devices/{userDeviceID}/error-codes:
get:
parameters:
Expand Down Expand Up @@ -1586,33 +1560,6 @@ paths:
- device
- integration
- command
/user/devices/{userDeviceID}/vin:
patch:
consumes:
- application/json
description: Deprecated. updates the VIN on the user device record. Keeping
this alive to not break mobile app. VIN's now come from attestations.
parameters:
- description: VIN
in: body
name: vin
required: true
schema:
$ref: '#/definitions/internal_controllers.UpdateVINReq'
- description: user id
in: path
name: userDeviceID
required: true
type: string
produces:
- application/json
responses:
"204":
description: No Content
security:
- BearerAuth: []
tags:
- user-devices
/user/devices/{userDeviceId}/commands/update-nft-image:
post:
description: Updates a user's NFT image.
Expand Down
16 changes: 8 additions & 8 deletions internal/controllers/device_data_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestUserDevicesController_QueryDeviceErrorCodes(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.QueryDeviceErrorCodes)
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, nil), c.QueryDeviceErrorCodes)

t.Run("POST - get description for query codes", func(t *testing.T) {
req := QueryDeviceErrorCodesReq{
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestUserDevicesController_ShouldErrorOnTooManyErrorCodes(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.QueryDeviceErrorCodes)
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, nil), c.QueryDeviceErrorCodes)

t.Run("POST - get description for query codes", func(t *testing.T) {

Expand Down Expand Up @@ -249,7 +249,7 @@ func TestUserDevicesController_ShouldErrorInvalidErrorCodes(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.QueryDeviceErrorCodes)
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, nil), c.QueryDeviceErrorCodes)

t.Run("POST - get description for query codes", func(t *testing.T) {

Expand Down Expand Up @@ -319,7 +319,7 @@ func TestUserDevicesController_ShouldErrorOnEmptyErrorCodes(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.QueryDeviceErrorCodes)
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, nil), c.QueryDeviceErrorCodes)

t.Run("POST - get description for query codes", func(t *testing.T) {

Expand Down Expand Up @@ -389,7 +389,7 @@ func TestUserDevicesController_ShouldStoreErrorCodeResponse(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.QueryDeviceErrorCodes)
app.Post("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, nil), c.QueryDeviceErrorCodes)

t.Run("POST - get description for query codes", func(t *testing.T) {
erCodeReq := []string{"P0017", "P0016"}
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestUserDevicesController_GetUserDevicesErrorCodeQueries(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Get("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID), c.GetUserDeviceErrorCodeQueries)
app.Get("/user/devices/:userDeviceID/error-codes", test.AuthInjectorTestHandler(testUserID, nil), c.GetUserDeviceErrorCodeQueries)

t.Run("GET - all saved error code response for current user devices", func(t *testing.T) {

Expand Down Expand Up @@ -551,7 +551,7 @@ func TestUserDevicesController_ClearUserDeviceErrorCodeQuery(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes/clear", test.AuthInjectorTestHandler(testUserID), c.ClearUserDeviceErrorCodeQuery)
app.Post("/user/devices/:userDeviceID/error-codes/clear", test.AuthInjectorTestHandler(testUserID, nil), c.ClearUserDeviceErrorCodeQuery)

t.Run("POST - clear last saved error code response for current user devices", func(t *testing.T) {
autoPiInteg := test.BuildIntegrationGRPC(ksuid.New().String(), constants.AutoPiVendor, 10, 0)
Expand Down Expand Up @@ -638,7 +638,7 @@ func TestUserDevicesController_ErrorOnAllErrorCodesCleared(t *testing.T) {
testUserID := "123123"
c := NewUserDevicesController(&config.Settings{Port: "3000"}, pdb.DBS, &mockDeps.logger, mockDeps.deviceDefSvc, mockDeps.deviceDefIntSvc, &fakeEventService{}, mockDeps.scClient, mockDeps.scTaskSvc, mockDeps.teslaSvc, mockDeps.teslaTaskService, nil, nil, mockDeps.autoPiIngest, mockDeps.deviceDefinitionIngest, nil, nil, nil, mockDeps.openAISvc, nil, nil, nil, nil, nil, nil, nil, nil)
app := fiber.New()
app.Post("/user/devices/:userDeviceID/error-codes/clear", test.AuthInjectorTestHandler(testUserID), c.ClearUserDeviceErrorCodeQuery)
app.Post("/user/devices/:userDeviceID/error-codes/clear", test.AuthInjectorTestHandler(testUserID, nil), c.ClearUserDeviceErrorCodeQuery)

t.Run("POST - clear last saved error code response for current user devices", func(t *testing.T) {
autoPiInteg := test.BuildIntegrationGRPC(ksuid.New().String(), constants.AutoPiVendor, 10, 0)
Expand Down
Loading

0 comments on commit 22efd8d

Please sign in to comment.