Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some additional checks to avoid false positives with existing VIN #432

Merged
merged 4 commits into from
Jan 23, 2025
Merged
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
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
Loading