google-code-export / yabi

Automatically exported from code.google.com/p/yabi
0 stars 1 forks source link

Yabi admin json interface for adding credentials marking everything as encrypted #15

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We have been streamlining adding of users details to yabi using the json 
interface kindly supplied by @aharvey. However recently we've been having 
trouble with it marking all the credentials as encrypted and encrypt_on_login 
as both True.

In our scripts we use:

    # need to add credentials
    $credential{'dummy'} = searchObject($browser, 'credential', "?description__exact=dummy credential&username__exact=$username");
    if ($credential{'dummy'} < 0) {
        # Create dummy credential
        %json = (
            'last_modified_by' => $YABIADMIN,
            'created_by' => $YABIADMIN,
            'username' => "bioflow",
            'description' => 'dummy credential',
            'user' => $user_id,
            'encrypt_on_login' => 'f',
            'encrypted' => 'f'
        );

        $credential{'dummy'} = createObject($browser, \%json, 'credential');
    }
    print "Dummy credential is $credential{'dummy'}\n";
Can you check to make sure we are using the correct field names that match up 
with what the models are expecting.

Thanks.

Original issue reported on code.google.com by ahunter.ccg@gmail.com on 7 Jul 2011 at 1:24

GoogleCodeExporter commented 9 years ago

Original comment by ahunter.ccg@gmail.com on 7 Jul 2011 at 7:09

GoogleCodeExporter commented 9 years ago

Original comment by aahun...@gmail.com on 29 Jul 2011 at 3:33

GoogleCodeExporter commented 9 years ago

Original comment by retrogra...@gmail.com on 2 Aug 2011 at 8:09

GoogleCodeExporter commented 9 years ago
the parameter in the json for 'encrypt_on_login' and 'encypted' is 'f', and 'f' 
is a string not a boolean. All strings of non-zero length evaluate to be true, 
thus the encrypt flags are set to be true. 

JSON supports booleans. 
http://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_example

so if instead of sending the final encoding something like '.. "encrypted": "f" 
', you need to send '... "encrypted": false '

I can't see whats happening inside perl function creatObject(), but that will 
need to output the correct JSON data type.

As an example, the following works: 

{{{
curl -k -b cookie.txt -H "Content-Type: application/json; charset=UTF-8" -H 
"X-Requested-With: XMLHttpRequest" --data-binary '{"data": {"username": 
"bioflow", "last_modified_by": 1, "description": "dummy credential", 
"encrypted": false, "created_by": 1, "user": 1, "encrypt_on_login": false}}' 
https://faramir.localdomain/yabiadmin/cwellington/admin/yabi/credential/ext/json

{"message": "Created new record.", "data": {"username": "bioflow", 
"encrypt_on_login": "False", "description": "dummy credential", "encrypted": 
"False", "cert": "", "created_by": 1, "expires_on": "None", "created_on": 
"2011-08-03 11:54:51.136011", "backends": [], "last_modified_by": 1, "key": "", 
"user__unicode": "andrew", "last_modified_by__unicode": "django", "password": 
"", "created_by__unicode": "django", "id": "67", "last_modified_on": 
"2011-08-03 11:54:51.135955", "user": 1}, "success": true}
}}}

Notice the *returned* json has the wrong json data type in the fields ("False", 
rather than false). This is a bug in this json admin extension in Mango. 
Although the returned snippet is wrong, the correct data types are stored, and 
also returned if asked for but not through ext/json. The bug is in the 
serialise_record() method in django/contrib/webservices/ext.py and will be 
addressed in a later release.

Original comment by retrogra...@gmail.com on 3 Aug 2011 at 3:59

GoogleCodeExporter commented 9 years ago
Alerting sysadmins

Original comment by amacgregor on 11 Aug 2011 at 3:17