validate shared record code

This commit is contained in:
stremovsky
2019-12-19 10:47:48 +02:00
parent 30126381eb
commit 3f7813b3a5
4 changed files with 21 additions and 8 deletions

View File

@@ -29,6 +29,17 @@ RESULT=`curl -s http://localhost:3000/v1/userapp/token/$TOKEN/shipping \
-d '{"country":"Israel","address":"Allenby 1","postcode":"12345","status":"active"}' | jq ".status" | tr -d '"'`
echo "User shipping record created, status $RESULT"
RESULT=`curl -s http://localhost:3000/v1/sharedrecord/token/$TOKEN \
-H "X-Bunker-Token: "$DATABUNKER_APIKEY -H "Content-Type: application/json" \
-d '{"app":"shipping","fields":"address"}'`
echo "Shared record created, status $RESULT"
REC_ID=`echo $RESULT | jq ".record" | tr -d '"'`
echo $REC_ID
RESULT=`curl -s http://localhost:3000/v1/get/$REC_ID`
echo "Get shared record (no password/access token): $RESULT"
exit
RESULT=`curl -s http://localhost:3000/v1/userapp/token/$TOKEN \
-H "X-Bunker-Token: "$DATABUNKER_APIKEY -H "Content-Type: application/json"`
echo "View list of all user apps $RESULT"

View File

@@ -30,7 +30,7 @@ type listTbls struct {
Xtokens Tbl
Consent Tbl
Sessions Tbl
Sharedrecord Tbl
Sharedrecords Tbl
}
// Enum for public use
@@ -40,7 +40,7 @@ var TblName = &listTbls{
Xtokens: 2,
Consent: 3,
Sessions: 4,
Sharedrecord: 5,
Sharedrecords: 5,
}
type Config struct {
@@ -145,8 +145,8 @@ func (e mainEnv) setupRouter() *httprouter.Router {
router.GET("/v1/login/:mode/:address", e.userLogin)
router.GET("/v1/enter/:mode/:address/:tmp", e.userLoginEnter)
router.POST("/v1/record/:token", e.newSharedRecord)
router.GET("/v1/record/:record", e.getRecord)
router.POST("/v1/sharedrecord/token/:token", e.newSharedRecord)
router.GET("/v1/get/:record", e.getRecord)
router.GET("/v1/consent/:mode/:address", e.consentAllUserRecords)
router.GET("/v1/consent/:mode/:address/:brief", e.consentUserRecord)

View File

@@ -252,6 +252,8 @@ func getTable(t Tbl) string {
return "xtokens"
case TblName.Sessions:
return "sessions"
case TblName.Sharedrecords:
return "sharedrecords"
}
return "users"
}

View File

@@ -2,6 +2,7 @@ package main
import (
"errors"
"fmt"
"strings"
"time"
@@ -23,18 +24,17 @@ func (dbobj dbcon) saveSharedRecord(userTOKEN string, fields string, expiration
}
}
fmt.Printf("Expiration is : %s\n", expiration)
start, err := parseExpiration(expiration)
if err != nil {
return "", err
}
// check if user record exists
record, err := dbobj.lookupUserRecord(userTOKEN)
if record == nil || err != nil {
// not found
return "", errors.New("not found")
}
recordUUID, err := uuid.GenerateUUID()
if err != nil {
return "", err
@@ -55,7 +55,7 @@ func (dbobj dbcon) saveSharedRecord(userTOKEN string, fields string, expiration
if len(session) > 0 {
bdoc["session"] = session
}
_, err = dbobj.createRecord(TblName.Sharedrecord, bdoc)
_, err = dbobj.createRecord(TblName.Sharedrecords, bdoc)
if err != nil {
return "", err
}
@@ -67,7 +67,7 @@ func (dbobj dbcon) getSharedRecord(recordUUID string) (checkRecordResult, error)
if isValidUUID(recordUUID) == false {
return result, errors.New("failed to authenticate")
}
record, err := dbobj.getRecord(TblName.Sharedrecord, "record", recordUUID)
record, err := dbobj.getRecord(TblName.Sharedrecords, "record", recordUUID)
if record == nil || err != nil {
return result, errors.New("failed to authenticate")
}