[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-anastasis] 05/06: fix ahv validation
From: |
gnunet |
Subject: |
[taler-anastasis] 05/06: fix ahv validation |
Date: |
Tue, 10 Nov 2020 13:44:52 +0100 |
This is an automated email from the git hooks/post-receive script.
dennis-neufeld pushed a commit to branch master
in repository anastasis.
commit 9fbcdb9f8a74945787b7ce0d4f912e62c80f8823
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Tue Nov 10 13:44:15 2020 +0100
fix ahv validation
---
contrib/redux.ch.json | 2 +-
...test_anastasis_reducer_enter_user_attributes.sh | 2 +-
src/cli/test_anastasis_reducer_select_country.sh | 6 ++-
src/include/anastasis_redux.h | 14 +++++++
src/lib/anastasis_api_backup_redux.c | 19 ---------
src/lib/anastasis_api_redux.c | 45 ++++++++++++++--------
6 files changed, 49 insertions(+), 39 deletions(-)
diff --git a/contrib/redux.ch.json b/contrib/redux.ch.json
index 075ac6a..c8bd3dc 100644
--- a/contrib/redux.ch.json
+++ b/contrib/redux.ch.json
@@ -26,7 +26,7 @@
"de_CH":"AHV-Nummer"
},
"widget": "anastasis_gtk_ia_ahv",
- "validation": "^(756)\\.[0-9]{4}\\.[0-9]{4}\\.[0-9]{2}|(756)[0-9]{10}$"
+ "validation": "^(756).[0-9]{4}.[0-9]{4}.[0-9]{2}|(756)[0-9]{10}$"
}
]
}
diff --git a/src/cli/test_anastasis_reducer_enter_user_attributes.sh
b/src/cli/test_anastasis_reducer_enter_user_attributes.sh
index cdb22ec..fffc87b 100755
--- a/src/cli/test_anastasis_reducer_enter_user_attributes.sh
+++ b/src/cli/test_anastasis_reducer_enter_user_attributes.sh
@@ -52,7 +52,7 @@ echo "Test user attributes collection in a backup state"
./anastasis-reducer -a \
'{"identity_attributes": {
"full_name": "Max Musterman",
- "social_security_number": "123456789",
+ "ahv_number": "756.9217.0769.85",
"birth_year": 2000 ,
"birth_month": 1,
"birth_day": 1}}' \
diff --git a/src/cli/test_anastasis_reducer_select_country.sh
b/src/cli/test_anastasis_reducer_select_country.sh
index 92ca397..ea2049f 100755
--- a/src/cli/test_anastasis_reducer_select_country.sh
+++ b/src/cli/test_anastasis_reducer_select_country.sh
@@ -102,7 +102,11 @@ echo " "
echo "Test country selection in a backup state"
./anastasis-reducer -b $SFILE
./anastasis-reducer -a '{"continent": "Europe"}' select_continent $SFILE $TFILE
-./anastasis-reducer -a '{"country": "Switzerland", "country_code": "ch",
"currency":"TESTKUDOS"}' select_country $TFILE $SFILE
+./anastasis-reducer -a \
+ '{"country": "Switzerland",
+ "country_code": "ch",
+ "currency":"TESTKUDOS"}' \
+ select_country $TFILE $SFILE
STATE=`jq -r -e .backup_state < $SFILE`
if test "$STATE" != "USER_ATTRIBUTES_COLLECTING"
diff --git a/src/include/anastasis_redux.h b/src/include/anastasis_redux.h
index d7e8050..143c967 100644
--- a/src/include/anastasis_redux.h
+++ b/src/include/anastasis_redux.h
@@ -227,4 +227,18 @@ ANASTASIS_redux_action (const json_t *state,
void *cb_cls);
+/**
+ * Function to return a json error response.
+ *
+ * @param cb callback to give error to
+ * @param cb_cls callback closure
+ * @param ec error code
+ * @param detail error detail
+ */
+void
+ANASTASIS_redux_fail (ANASTASIS_ActionCallback cb,
+ void *cb_cls,
+ enum TALER_ErrorCode ec,
+ const char *detail);
+
#endif /* _ANASTASIS_REDUX_H */
diff --git a/src/lib/anastasis_api_backup_redux.c
b/src/lib/anastasis_api_backup_redux.c
index 96d51d3..831f8e1 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -37,25 +37,6 @@ static const char *backup_strings[] = {
#undef GENERATE_STRING
-void
-ANASTASIS_redux_fail (ANASTASIS_ActionCallback cb,
- void *cb_cls,
- enum TALER_ErrorCode ec,
- const char *detail)
-{
- json_t *estate;
-
- estate = json_pack ("{s:s?, s:I, s:s}",
- "detail", detail,
- "code", (json_int_t) ec,
- "hint", TALER_ErrorCode_get_hint (ec));
- cb (cb_cls,
- ec,
- estate);
- json_decref (estate);
-}
-
-
enum ANASTASIS_BackupState
ANASTASIS_backup_state_from_string (const char *state_string)
{
diff --git a/src/lib/anastasis_api_redux.c b/src/lib/anastasis_api_redux.c
index 0eed76d..09c1cf7 100644
--- a/src/lib/anastasis_api_redux.c
+++ b/src/lib/anastasis_api_redux.c
@@ -62,6 +62,25 @@ ANASTASIS_generic_state_to_string (enum
ANASTASIS_GenericState gs)
}
+void
+ANASTASIS_redux_fail (ANASTASIS_ActionCallback cb,
+ void *cb_cls,
+ enum TALER_ErrorCode ec,
+ const char *detail)
+{
+ json_t *estate;
+
+ estate = json_pack ("{s:s?, s:I, s:s}",
+ "detail", detail,
+ "code", (json_int_t) ec,
+ "hint", TALER_ErrorCode_get_hint (ec));
+ cb (cb_cls,
+ ec,
+ estate);
+ json_decref (estate);
+}
+
+
/**
* How long do we wait at most for a /config reply from an Anastasis provider.
* 60s is very generous, given the tiny bandwidth required, even for the most
@@ -513,7 +532,7 @@ validate_ahv (const char *ahv_number,
{
num_to_check[7 + i] = ahv_number[9 + i];
}
- num_to_check[11] = ahv_number[15];
+ num_to_check[11] = ahv_number[14];
}
else
{
@@ -696,14 +715,10 @@ select_country (json_t *state,
{
if (NULL == arguments)
{
- json_t *error = json_pack ("{s:I, s:s}",
- "code",
- (json_int_t) ANASTASIS_EC_INVALID,
- "hint",
- "Arguments missing!");
- cb (cb_cls,
- ANASTASIS_EC_INVALID,
- error);
+ ANASTASIS_redux_fail (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_ARGUMENTS_MISSING,
+ "select_country");
return NULL;
}
@@ -929,14 +944,10 @@ enter_user_attributes (json_t *state,
{
if (NULL == arguments)
{
- json_t *error = json_pack ("{s:I, s:s}",
- "code",
- (json_int_t) ANASTASIS_EC_INVALID,
- "hint",
- "Arguments missing!");
- cb (cb_cls,
- ANASTASIS_EC_INVALID,
- error);
+ ANASTASIS_redux_fail (cb,
+ cb_cls,
+ TALER_EC_ANASTASIS_REDUCER_ARGUMENTS_MISSING,
+ "enter_user_attributes");
return NULL;
}
json_t *attributes = json_object_get (arguments,
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-anastasis] branch master updated (4ed7e40 -> 5f18ee4), gnunet, 2020/11/10
- [taler-anastasis] 01/06: fix return value from main() when run with -h/-v, gnunet, 2020/11/10
- [taler-anastasis] 02/06: redux - test continent selection, gnunet, 2020/11/10
- [taler-anastasis] 03/06: redux - testing country selection, gnunet, 2020/11/10
- [taler-anastasis] 06/06: Merge branch 'master' of ssh://git.taler.net/anastasis, gnunet, 2020/11/10
- [taler-anastasis] 04/06: testing user attributes collection, gnunet, 2020/11/10
- [taler-anastasis] 05/06: fix ahv validation,
gnunet <=